为了账号安全,请及时绑定邮箱和手机立即绑定

控制台访问不到vue对象的属性?

控制台访问不到vue对象的属性?

window.onload = function(){     var app = new Vue({         el: "#app",         data: {             foodList: [                 {                     name: "葱",                     price: 2.1,                     discount: 0.9                 },                 {                     name: "姜",                     price: 5.2,                     discount: 0.2                 },                 {                     name: "蒜",                     price: 0.8,                     discount: 0.8                 }             ]         }     }) }<div id="app">     <ul>         <li v-for="food in foodList">{{food.name}}: ¥{{food.price * food.discount}}</li>     </ul> </div>控制台可以访问到app对象,但不能访问到app.foodList,值为undefined。mac平台,safari和chrome都是这样。
查看完整描述

3 回答

?
习惯受伤

TA贡献885条经验 获得超1144个赞

foodList是data里的数据,你应该这样使用
app.data.foodList

查看完整回答
1 反对 回复 2018-01-02
?
堂堂堂堂糖糖糖童鞋

TA贡献101条经验 获得超58个赞

var app = new Vue({
        el: "#app",
        data () {
            return {
                foodList: [
                    {
                        name: "葱",
                        price: 2.1,
                        discount: 0.9
                    },
                    {
                        name: "姜",
                        price: 5.2,
                        discount: 0.2
                    },
                    {
                        name: "蒜",
                        price: 0.8,
                        discount: 0.8
                    }
                ]
            }
        }
    })


查看完整回答
反对 回复 2018-01-02
  • 3 回答
  • 0 关注
  • 6926 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信