一个简单的Vue.js组件开发示例
2024-10-07 07:29:48
//创建属于自己的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>
最新文章
- 烂泥:KVM、kickstart与NFS集成
- android MSM8974 上DeviceTree简介
- 使用ASP.Net WebAPI构建REST服务(六)——Self-Host
- 自动生成Makefile时,关于Makefile.am编写
- setTimeout setInterval 区别 javascript线程解释
- oracle手动启动服务
- Android(java)学习笔记135:Android中assets文件夹资源的访问
- layer弹窗插件实战用法小结1—— layer.alert()
- 十年过去了,各位 .net 兄弟还好吗
- C#之异步
- springmvc跨域+token验证(app后台框架搭建二)
- CUDA学习,使用shared memory实现Reverse Array
- 高性能缓存系统Memcached在ASP.NET MVC中应用
- 目前的.NET 主流的后端ORM框架
- 在python中使用print()时,raw write()返回无效的长度:OSError: raw write() returned invalid length 254 (should have been between 0 and 127)
- VMware虚拟机扩展Ubuntu系统磁盘空间
- 源码编译、安装net-snmp的方法和遇到的问题
- mint-ui Infinite scroll 重复加载、加载无效的原因及解决方案
- 云中树莓派(5):利用 AWS IoT Greengrass 进行 IoT 边缘计算
- flask再学习-重构!启动!
热门文章
- 【leetcode】1186. Maximum Subarray Sum with One Deletion
- SQL Server 2012 sa 用户登录 18456 错误 (转)
- yii 1.1简单文件缓存
- Java中String类中常用的方法
- reduce、map、zip、filter使用记录
- 改变主程序的入口 main
- 双三次插值C代码(利用opencv)
- @Aspect 注解切面解析
- Linux_KVM虚拟机
- Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu