美文网首页
共用的TagType组件折腾小记

共用的TagType组件折腾小记

作者: 郝艳峰Vip | 来源:发表于2018-11-01 14:55 被阅读0次

前沿:

一个tap页点击切换的共用的组件。如图所示:


微信图片_20180822161727.png
step1:新建一个tapTag.vue,内容如下
<template>
    <div class="TagTypeMoudle">
        <span class="flagButton"
              v-for="(item,index) in UnderTheFlagType"
              v-bind:key="index"
              @click="flagButton(index,item)"
              :class="{'flagButtonClick':isClickFlag == index}">{{item}}</span>
    </div>
</template>
<script>
export default {
  //父组件传过来的有几个tag以及tag上的文字。
    props:['UnderTheFlagType'],
    data(){
        return{
        isClickFlag:0,
        }
    },
      methods: {
      flagButton(index,item){
         this.isClickFlag = index;
        //  发射到父组件的方法,在父组件内可以触发该方法  
         this.$emit('FlagtoFather',item);
      }
  }
};
</script>
<style lang="scss" scoped>
@import "../../styles/myBase.scss";
.TagTypeMoudle {
  width: 100%;
  height: 50px;
  text-align: center;
  .flagButton {
    display: inline-block;
    width: 84px;
    height: 30px;
    line-height: 30px;
    background: #f3f3f3;
    font-size: 12px;
    color: #797979;
    border-radius: 2px;
    margin-right: 5px;
  }
  .flagButton:hover {
    background: $HomeBgColor;
    color: #ffffff;
    cursor: pointer;
  }
  .flagButtonClick {
    background: $HomeBgColor;
    color: #ffffff;
  }
}
</style>

step2:在需要引用的页面引入即可
<template>
     <tagType :UnderTheFlagType="UnderTheFlagType"
               v-on:FlagtoFather="fromFlag"></tagType>
</template>
import tagType from '@/components/TagType/index';
import { getFundCompanyFundPerformance } from '@/api/basicManage';
export default {
  components: {
    tagType
  },
  data() {
    return {
      //控制tag的文字以及数量  
      UnderTheFlagType: [
        '股票型',
        '混合型',
        '债券型',
        '货币型',
        'QDII',
        '其他'
      ],
    }
  },
methods:{
//在此触发子组件内的事件。
   fromFlag(item) {
      console.log(item)
}
}

结束:至此,一个闭合的公用tag组件就可以使用了,希望伙伴们多多指教

相关文章

  • 共用的TagType组件折腾小记

    前沿: 一个tap页点击切换的共用的组件。如图所示: step1:新建一个tapTag.vue,内容如下 step...

  • vue3 批量注册全局组件(共用组件)

    vue2中引入共用组件 main.js 中引入 就可以了! vue3中引入共用组件 main.js 中引入 就可以...

  • 初步尝试开发并发布自己的npm依赖包

    在公司开发项目时,在不同的项目中很容易遇到可以共用的组件或可以共用的函数方法。而我们通常的做法是将项目中可以共用的...

  • 《折腾》小记

    /你说你闹什么? 该你吃的一口不少啊(不能吃的一口不能)! 该你喝的一样不丢啊(不该喝的一样不行)! 不缺吃不缺喝...

  • 折腾小记

    今天把次卧折腾了一遍。原来买的双人高低床,在次卧的布局上格外的不合理,空间浪费较多,生活空间被挤压的较小,忍了两年...

  • vue的部分基础组件

    组件的基础 # 组件基础 ## 什么是组件 >对我们的页面中的共用的元素,进行拆分,单独做成一个模块,方便后续的使...

  • 【Flutter】多组件共用状态,父组件状态传递给子组件

    场景:多个组件共用一个状态,子组件通过方法改变父组件状态思路:状态和管理方法定义在父组件,通过构造函数传递给子组件...

  • 学跳绳小记

    学跳绳小记 或许你会说“你都多大了,还学跳绳?瞎折腾” 不过才四十出头而已。趁着现在还能折腾就折腾...

  • Vuex状态管理

    1.组件共用Store修改state更新到组件 2.原理图 3.代码 import Vuex from 'Vuex...

  • 前端架构之路(6) - 组件化

    组件化 1. 什么是 “组件化” 组件化就是将项目中可以共用的代码提取出来,单独成一个组件,以便在多个地方调用此组...

网友评论

      本文标题:共用的TagType组件折腾小记

      本文链接:https://www.haomeiwen.com/subject/msrxxqtx.html