vue之component中的template另一种定义方式
index.html:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title>&l
·
index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .red{ background:#FF0000; } </style> </head> <body> <div id="app"> <like></like> </div> <template id="like-component-tpl"> <button :class="{red: liked}" @click="on_click">赞{{liked_count}}</button> </template> <script src="../lib/vue.js"></script> <script src="./js/main.js"></script> </body> </html>
main.js:
Vue.component('like', { template: '#like-component-tpl', data: function(){ return { liked_count: 10, liked: false } }, methods: { on_click: function(){ if(!this.liked){ this.liked_count++; this.liked = true }else{ this.liked_count--; this.liked = false; } } } }) new Vue({ el: '#app' })
更多推荐
已为社区贡献16条内容
所有评论(0)