前提・実現したいこと
今vue.jpを勉強しているところでVue Masteryのレッスン5にいるのですが
https://www.vuemastery.com/courses/intro-to-vue-js/event-handling
同じようにしてもメソッドがうまく働きません。
あちこちで答えを探しているのですが最終的にここで何が悪いのか教えて頂きたく質問しました。どうぞ宜しくお願いします。
発生している問題・エラーメッセージ
addToCart is not defined
該当のソースコード
HTML
1 <div id="app"> 2 <div class="product"> 3 4 <div class="product-image"> 5 <img v-bind:src="image"> 6 </div> 7 8 <div class="product-info"> 9 <h1>{{ product }}</h1> 10 <p v-if="inventory > 10">In Stock</p> 11 <p v-else-if="inventory <= 10 && inventory > 0">Almost Sold Out!</p> 12 <p v-else>Out of Stock</p> 13 <ul> 14 <li v-for="detail in details">{{ detail }}</li> 15 </ul> 16 <ul> 17 <li v-for="size in sizes">{{ size }}</li> 18 </ul> 19 <div v-for="variant in variants" :key="variant.variantId"> 20 <p @mouseover="updateProduct(variant.variantImage)">{{ variant.variantColor }}</p> 21 </div> 22 <button v-on:click="addToCart">Add to Cart</button> 23 <div class="cart"> 24 <p>Cart({{cart}})</p> 25 </div> 26 </div> 27 </div> 28 </div>
JS
1var app = new Vue({ 2 el: '#app', 3 data: { 4 product: 'Socks', 5 image: './assets/vmSocks-green.png', 6 inventory: 19, 7 details: ["80% cotton", "20% polyester", "Gender-neutral"], 8 variants: [ 9 { 10 variantId: 2234, 11 variantColor: "green", 12 variantImage: "./assets/vmSocks-green.png" 13 }, 14 { 15 variantId: 2235, 16 variantColor: "blue", 17 variantImage: "./assets/vmSocks-blue.png" 18 } 19 ], 20 sizes: ["XS", "S", "M", "L", "XL"], 21 cart: 0, 22 methods: { 23 addToCart(){ 24 this.cart += 1 25 }, 26 updateProduct(variantImage){ 27 this.image = variantImage 28 } 29 } 30 } 31})
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/02 06:15