标签:ber 不可 ffffff char ola ext handle body family


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="app">
<button-counter></button-counter>
<button-counter></button-counter>
<button-counter></button-counter>
</div>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript">
/*
组件注册注意事项
1、组件参数的data值必须是函数,
之前实例化的时候是一个对象{},使用函数可以形成一个闭包环境,保证每一个组件都是拥有一份独立的数据
2、组件模板必须是单个根元素
<button @click="handle">点击了{{count}}次</button><button>测试</button> ---不行
解决方法:<div><button @click="handle">点击了{{count}}次</button><button>测试</button></div>
3、组件模板的内容可以是模板字符串
( ``,因为放在一行内,不直观造成代码可读性差)
*/
Vue.component("button-counter", {
data: function () {
return {
count: 0,
};
},
// template: ‘<div><button @click="handle">点击了{{count}}次</button><button>测试</button></div>‘,
template: `
<div>
<button @click="handle">点击了{{count}}次</button>
<button>测试123</button>
</div>
`,
methods: {
handle: function () {
this.count += 2;
},
},
});
var vm = new Vue({
el: "#app",
data: {
},
});
</script>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<hello-world></hello-world>
<hello-tom></hello-tom>
<hello-jerry></hello-jerry>
<test-com></test-com>
</div>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript">
/*
局部组件注册
局部组件只能在注册他的父组件中使用
*/
Vue.component(‘test-com‘,{
template: ‘<div>Test<hello-world></hello-world></div>‘,
//全局组件中不可用,只能在注册他的父组件中使用 <div id="app"></div>
});
var HelloWorld = {
data: function(){
return {
msg: ‘HelloWorld‘
}
},
template: ‘<div>{{msg}}</div>‘
};
var HelloTom = {
data: function(){
return {
msg: ‘HelloTom‘
}
},
template: ‘<div>{{msg}}</div>‘
};
var HelloJerry = {
data: function(){
return {
msg: ‘HelloJerry‘
}
},
template: ‘<div>{{msg}}</div>‘
};
var vm = new Vue({
el: ‘#app‘,
data: {
},
components: {
‘hello-world‘: HelloWorld,
‘hello-tom‘: HelloTom,
‘hello-jerry‘: HelloJerry
}
});
</script>
</body>
</html>
标签:ber 不可 ffffff char ola ext handle body family
原文地址:https://www.cnblogs.com/tusong1126/p/13234316.html