<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<title></title>
</head>
<body>
<div id="app">
<!-- 自定义组件 -->
<button-counter title="myTitle"></button-counter>
<div v-for="item in titles">
<button-counter v-bind:title="item"></button-counter>
</div>
<todo>
<todo-mytitle slot="todo-mytitle" v-bind:title="title"></todo-mytitle>
<todo-content slot="todo-content" v-bind:content="content"></todo-content>
</todo>
<!-- 插槽 -->
</div>
</body>
<script>
// 定义一个名为 button-counter 的新组件 全局注册
Vue.component('button-counter', {
// 一个组件的 data 选项必须是一个函数
data: function () {
return {
count: 0
}
},
//在组件上注册的一些自定义 attribute 使用 v-bind 来动态传递 prop
props: ['title'],
template: '<button v-on:click="count++">{{title}} You clicked me {{count}} times.</button>'
})
// 插槽
Vue.component("todo",{
template:'<div> <slot name=\'todo-mytitle\'></slot> <slot name=\'todo-content\'></slot> </div>'
})
Vue.component("todo-mytitle",{
props: ['title'],
template:'<div>{{title}}</div>'
})
Vue.component("todo-content",{
props: ['content'],
template:'<div>{{content}}</div>'
})
var app = new Vue({
el: '#app',
data : {
titles : [
"title1","title2"
],
title: "str",
content: "sss"
},
})
</script>
</html>
标签:Vue,title,component,content,template,组件
From: https://www.cnblogs.com/lwx11111/p/16942404.html