首页 > 其他 > 详细

对组件库对再次封装

时间:2019-03-27 13:26:38      阅读:147      评论:0      收藏:0      [点我收藏+]

自定义button组件,(在cube组件库的基础上再次封装)

MButton.vue

<template>
  <div class="button">
    <cube-button class="selfbtn" primary>
      <slot>{{ text }}</slot>
    </cube-button>
  </div>
</template>

<script>
export default {
  name: ‘MButton‘,
  props: {
    text: String
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.selfbtn{
  width: 90%;
  margin: 30px auto 0 auto;
  border-radius: 8px;
  font-size: 20px;
}
</style>

 

考虑到这种按钮每个页面都有用到,可以在main.js中引入

import MButton from ‘@/components/common/MButton.vue‘

Vue.component(MButton.name, MButton)

技术分享图片

 

注意:

1,组件引入的位置是在cube-ui的后面;

2,原本也是用Vue.use(MButton),这样会出错,所以换成Vue.component(MButton.name, MButton)就没有问题了

 

在使用的页面中就可以直接用了

<m-button @click.native="nextFn">下一步</m-button>

注意:

给vue组件绑定事件时候,必须加上native ,不然不会生效(监听根元素的原生事件,使用 .native 修饰符)

 

总结:

组件的引入和事件绑定

对组件库对再次封装

原文:https://www.cnblogs.com/wang715100018066/p/10606596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!