Vue.js 添加组件
2016-03-31 14:08
701 查看
<!DOCTYPE HTML> <html> <head> <title>vue.js hello world</title> <script src="../vue.js"></script> </head> <body> <div id="example"> <my-component v-on:click="cao"></my-component> </div> <script> // 定义 var MyComponent = Vue.extend({ template: '<div>A custom component!</div>' }); // 注册 Vue.component('my-component', MyComponent); // 创建根实例 new Vue({ el: '#example', methods:{ cao:function(event){ alert(event.target.tagName); } } }); </script> </body> </html>
效果:
局部注册
不需要全局注册每个组件。可以让组件只能用在其它组件内,用实例选项components注册:
var Child = Vue.extend({ /* ... */ }) var Parent = Vue.extend({ template: '...', components: { // <my-component> 只能用在父组件模板内 'my-component': Child } })
相关文章推荐
- ios CAShapeLayer和UIBezierPath
- iOS在更改用户头像并保存至本地沙盒目录中对于UIImagePickerController、UIAlertController的使用
- [UITableView _endCellAnimationsWithContext:]
- iOS基本UI控件总结
- #学习笔记#(56)angular ui-router使用姿势
- An AnnotationConfiguration instance is required to use.....异常
- php中的continue用法
- iOS-一个对UIAlertController的封装类分享
- iOS: setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.
- iOS UITableViewController出现crash
- 从response.header中提取cookie,在request里添加cookie
- 从response.header中提取cookie,在request里添加cookie
- UItableView的两个重用机制区别
- UI练习
- requests用法
- JAVA GUI之CardLayout
- 客户端窗口UI管理
- request.getInputStream()只能获取一次的问题
- UICollectionViewLayout
- 270. Closest Binary Search Tree Value