<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script src="vue.min.js"></script> </head> <body> <div id="app-div"> <h1>{{msg}}</h1> <h1>{{ gree('hzz') }}</h1> <a v-bind:href="baidu">百度</a> <p v-html="baiduTag"></p> <p>{{ age }}</p> <button @click="add(2)">加</button> <button @click="add(-3)">减</button> <div id="canvas" @mousemove="updateXY"> ({{ x }},{{ y }}) </div> <a @click.prevent="alert" href="http://www.baidu.com">a标签</a> <input type="text" ref="name" @keyup="setName"/> <input type="text" ref="age" @keyup="setAge"/> <span>{{name}}</span> <span>{{age}}</span> </div> </body> <script src="app.js"></script> </html>
new Vue({ el:'#app-div', data:{ msg:'this is a vue test', baidu:'http://www.baidu.com/', baiduTag:'<a href="http://www.baidu.com/">百度Tag</a>', age:29, x:0, y:0, name:'' }, methods:{ gree:function(name){ return 'hello '+name + this.msg; }, add:function(x){ this.age+=x; }, updateXY:function(e){ this.x=e.pageX; this.y=e.pageY; }, alert:function(){ alert('hello world!'); }, setName:function () { this.name=this.$refs.name.value; }, setAge:function(){ this.age=this.$refs.age.value; } } });