<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Index Page</title> </head> <body> <form action="" id="demo"> <input type="text" value="调试 vuejs 2.0" ref="input1"> <a href="javascript:void(0)" v-on:click="test1">测试</a> <br> <span>{{ result1 }}</span> <br> <input type="text" v-model="input2"> <a href="javascript:void(0)" v-on:click="test2">测试</a> <br> <span>{{ result2 }}</span> </form> <script src="http://cdn.bootcss.com/vue/2.0.3/vue.min.js"></script> <script type="text/javascript" src="demo.js"></script> </body> </html>
new Vue({ el: "#demo", data: { result1: null, result2: null, input2: "" }, created: function() { // the created hook is called after the instance is created }, methods: { test1: function () { this.result1 = this.$refs.input1.value + " 成功!"; }, test2: function () { this.result2 = this.input2 + " 成功!"; } } })
本文通过一个简单的实例介绍了如何使用 Vue.js 2.0 进行页面元素的绑定与事件处理。示例中包含了利用 ref 获取 input 元素值的方法以及使用 v-model 实现输入框值的双向绑定。
130

被折叠的 条评论
为什么被折叠?



