vue.js1.0版本
可以通過:v-el 來取得dom元素
例如:
html代碼:
<input type="text" name="xxx" id="xxx" v-el:sxx /> <button @click="ok()">確定</button>
js代碼:
var vm = new Vue({ el: '#app', methods: { ok() { var xx = this.$els.sxx.value; console.log(xx); } } });
結果:

Vue.js2.0
Vue.js 2.0使用了 ref 替換掉了 v-el和v-ref,使用 ref 屬性來標識一個元素。 .
我們寫的時候就變成了
<input type="text" name="xxx" id="xxx" ref='sxx' /> <button @click="ok()">確定</button>
調用時還是一樣的
var vm = new Vue({ el: '#app', methods: { ok() { var xx = this.$refs.sxx.value; console.log(xx); } } });
