//创建属于自己的vue组件库
(function(Vue, undefined) {
Vue.component("my-component", {
template: '<div @click="alertName">{{message.name}}<button @click="alertMessage">{{message.age}}</button></div>',//模板最外层必须只有一个标签包裹,不能同时存在两个
props: ['message'],
data: function() {
return { }
},
methods: {
alertName() {
this.$emit('alerta')//事件名称必须小写,不然无效(此处浪费了我好长时间)
},
alertMessage(){
this.$emit('alertmessage',this.message.name)
}
}
})
}(Vue))

  

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="vue.js"></script>
<script type="text/javascript" src="iview.js"></script>
</head>
<body>
<div id="example">
<my-component :message="great" @alerta="alet" @alertmessage='alertb'></my-component>
</div> <script type="text/javascript">
var vue=new Vue({
el: '#example',
data:{
great:{
name:'wanglu',
age:12
}
},
methods:{
alet(){
this.great={name:'liuyu',age:13};
},
alertb(name){
alert(name);
}
}
})
</script> </body>
</html>

  

最新文章

  1. 烂泥:KVM、kickstart与NFS集成
  2. android MSM8974 上DeviceTree简介
  3. 使用ASP.Net WebAPI构建REST服务(六)——Self-Host
  4. 自动生成Makefile时,关于Makefile.am编写
  5. setTimeout setInterval 区别 javascript线程解释
  6. oracle手动启动服务
  7. Android(java)学习笔记135:Android中assets文件夹资源的访问
  8. layer弹窗插件实战用法小结1—— layer.alert()
  9. 十年过去了,各位 .net 兄弟还好吗
  10. C#之异步
  11. springmvc跨域+token验证(app后台框架搭建二)
  12. CUDA学习,使用shared memory实现Reverse Array
  13. 高性能缓存系统Memcached在ASP.NET MVC中应用
  14. 目前的.NET 主流的后端ORM框架
  15. 在python中使用print()时,raw write()返回无效的长度:OSError: raw write() returned invalid length 254 (should have been between 0 and 127)
  16. VMware虚拟机扩展Ubuntu系统磁盘空间
  17. 源码编译、安装net-snmp的方法和遇到的问题
  18. mint-ui Infinite scroll 重复加载、加载无效的原因及解决方案
  19. 云中树莓派(5):利用 AWS IoT Greengrass 进行 IoT 边缘计算
  20. flask再学习-重构!启动!

热门文章

  1. 【leetcode】1186. Maximum Subarray Sum with One Deletion
  2. SQL Server 2012 sa 用户登录 18456 错误 (转)
  3. yii 1.1简单文件缓存
  4. Java中String类中常用的方法
  5. reduce、map、zip、filter使用记录
  6. 改变主程序的入口 main
  7. 双三次插值C代码(利用opencv)
  8. @Aspect 注解切面解析
  9. Linux_KVM虚拟机
  10. Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu