在封装好一个通用组件时,点击组件内的button,触发组件Button的点击事件(@click=”createTag”)需要通信,这是一种写法,当然会有更高级的写法,但是暂时先用这个,
第一种
通用组件

  1. <template>
  2. <button class="newTag" @click="$emit('click',$event)"> <slot /> </button>
  3. </template>
  4. <script lang='ts'>
  5. import Vue from 'vue';
  6. import {Component} from 'vue-property-decorator';
  7. @Component
  8. export default class Button extends Vue {
  9. }

引用组件

  1. <template>
  2. <Button @click="createTag">新增标签</Button>
  3. </template>

第二种

组件页不变,引用组件页加一个native,作用一样,只可意会,

引用组件页

  1. <template>
  2. <Button @click.native="createTag">新增标签</Button>
  3. </template>

更多相关文章

  1. Vue组件为什么data必须是一个函数呢?本文案例详解
  2. 深入浅出理解PHP原理之变量赋值
  3. PHP 服务器组件和变量
  4. vs code的插件配置、markdown和emmet基本语法
  5. adminlte框架后台模板分块
  6. react-redux源码不完全指北
  7. Vue 中的 .sync 修饰符stop修饰符prevent修饰符可以press.enter
  8. mysql语句、类的自动加载与引用
  9. Mysql与use引用

随机推荐

  1. android EditText中的inputType .
  2. android 环境搭建helloworld
  3. android移动数据上网的开关的实现
  4. 腾讯微博客户端开发视频--若水(第三集、第
  5. Android SDK 快速安装方法
  6. android获取APK签名信息及MD5指纹
  7. 【面包屑】快速使用RecyclerView搭建列表
  8. 修改ListView的分割线
  9. Android之Handler详解(四)
  10. Android LayoutInflater