<body>
<script type="text/javascript" src="js/vue.js" ></script>
<div id="app">
<counter heading="likes" color="green"></counter>
<counter heading="disLikes" color="red"></counter>
</div>
<template id="my-counter">
<!--
作者:offline
时间:2018-02-25
描述:必须要用div(其他也可以如p)包裹动态复用代码 否则会报
Component template should contain exactly one root element.
If you are using v-if on multiple elements,
use v-else-if to chain them instead.
的错误
-->
<div>
<h1>{{heading}}</h1>
<!--
vue2.x
不同版本绑定绑定动态style的方法是不一样的
v-bind:style
-->
<button @click="count++" v-bind:style="{'background': color}">{{count}}</button>
</div>
</template>
<script type="text/javascript">
Vue.component('counter',{
template:"#my-counter",
props:['heading','color'],
data:function(){
return {count:0}
}
})
var app =new Vue({
el:'#app',
})
</script>
</body>