最近在項目中使用了vue.js。在爬坑的路上遇到了很多問題。這里都會給記錄下來,今天要說的是怎么獲取自定義屬性的值。
HTML
<!DOCTYPE html> <html> <head> <script src="http://vuejs.org/js/vue.js"></script> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <div id="app"> <button v-for="list in items" @click="getType(list.type)" :type="list.type">click{{list.type}}</button> <p>type:{{type}}</p> </div> </body> </html>
Javascript
var vm = new Vue({ el:'#app', data:{ type:'', items:[ {type:1}, {type:2} ] }, methods:{ getType:function(type){ this.type = type } } })
在線demo:http://js.jirengu.com/wemefivime
更多內容請看 https://www.aaz5.com/