We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<!--1.导入vue--> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <!--2.html里面声明式的方式使用数据 --> <div id="app"> <h1>{{message}}</h1> </div> <script type="text/javascript"> //3. JS初始化一个Vue对象 var app=new Vue({ el:'#app', data:{ message:'hello vue!' } }) </script>
var app = new Vue({ //选项 })
var app = new Vue({ el:'#app' //el:document.getElementById('app') })
var app = new Vue({ el:'#app', data:{ name:'tom' } })
<div id="app"> <h2>{{name}}</h2> <!--通过指令表达式访问方法--> <button @click="sayHello">按钮</button> </div> <script type="text/javascript"> var app=new Vue({ el:"#app", data:{ name:'tom' }, methods:{ sayHello:function(){ //方法中的this自动绑定为Vue实例 console.log(this.name,this===app); } } }); //通过Vue实例访问方法 app.sayHello(); </script>
<div id="app"> <table class="table table-bordered table-striped"> <tr> <th>序号</th> <th>物品</th> <th>单价</th> <th>数量</th> <th>小计</th> </tr> <tr v-for="(good,index) in goods"> <td>{{index+1}}</td> <td>{{good.name}}</td> <td>{{good.price}}</td> <td><input type="number" min="0" v-model="good.count" /></td> <td>{{getSum(index)}}</td> </tr> <tr> <td colspan="4">总计</td> <td>{{getTotalSum}}</td> </tr> </table> </div>
var app = new Vue({ el: '#app', data: { goods: [{ name: '苹果', price: 55, count: 2 },{ name: '香蕉', price: 65, count: 3 }], }, methods:{ getSum:function(i){ return this.goods[i].price*this.goods[i].count; } }, computed: { getTotalSum: function() { var sum=0; for(var i=0;i<this.goods.length;i++){ sum+=this.goods[i].price*this.goods[i].count; } return sum; } } })
v-for
v-model
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Vue应用架构
Vue实例
选项
el选项
data选项
methods选项
computed选项
案例练习
可计算的表格
代码解析
代码解析
重点点化
v-for
指令的用法,v-model
指令的用法。The text was updated successfully, but these errors were encountered: