首页 > 其他 > 详细

vue 组件 组件2

时间:2018-03-04 10:53:32      阅读:184      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of page</title>
</head>
<body>
<div id="example">
<my-component></my-component>
</div>
<div id="example-2">
<simple-counter></simple-counter>
<simple-counter></simple-counter>
<simple-counter></simple-counter>
</div>

 


</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script >
var Child = {
template: ‘<div>A custom component!</div>‘
}
// 注册
// Vue.component(‘my-component‘, {
// template: Child
// })

// 创建根实例
new Vue({
el: ‘#example‘,
components: {
// <my-component> 将只在父组件模板中可用
‘my-component‘: Child
}
})
var data = { counter: 0 }

Vue.component(‘simple-counter‘, {
template: ‘<button v-on:click="counter += 1">{{ counter }}</button>‘,
// 技术上 data 的确是一个函数了,因此 Vue 不会警告,
// 但是我们却给每个组件实例返回了同一个对象的引用
data: function () {
return {
counter: 0
}
}
})

new Vue({
el: ‘#example-2‘
})
</script>
</html>

vue 组件 组件2

原文:https://www.cnblogs.com/dianzan/p/8504047.html

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