コンソールログエラーはありませんが、updated()
フック[現在のコードgetCartItems/
]に入れたものは、私が知らない何らかの理由で無限にレンダリングされます。私はalert('hi')
と設定してもそれを無限に警告します。だから私は何かがプロジェクトの値や何かを更新し続けていると思うが、私はどこにいるのかわからない。問題がどこにあるかを誰かに知らせることができますか?Vue 2 Laravel 5.3 Infinte Update Loop
カート-dropdown.vueあなたが更新フックにし、docsようVUEインスタンスのデータ変数carts
を更新している
<template>
<div class="row">
<div class="col-md-12">
<div class="row cart-dropdown-row" v-for="cart in carts">
<div class="col-md-3">
<div class="cart-dropdown-img-wrapper">
<img class="d-flex align-self-center cart-dropdown-img" :src="cart.product_choice.img1" alt="Generic placeholder image">
</div>
</div>
<div class="col-md-6 cart-dropdown-info-wrapper">
<h6 class="cart-dropdown-info">{{cart.product.name}}</h6>
</div>
<div class="col-md-3 cart-dropdown-qty-wrapper">
<div class="cart-dropdown-qty">x{{cart.qty}}</div>
</div>
</div>
</div>
<div class="row">
</div>
<div class="row cart-dropdown-checkout-wrapper">
<button type="button" class="btn btn-success btn-sm cart-dropdown-checkout" @click.prevent="goCheckout()">Check Out</button>
</div>
</div>
</template>
<script>
export default {
data(){
return{
carts:{},
}
},
props:[
],
mounted(){
this.getCartItems()
},
updated(){
this.getCartItems()
},
methods:{
getCartItems(){
var vm = this
vm.$http.get('/getCartItems/').then((response)=>{
vm.carts = response.data
});
},
goCheckout(){
window.location.href = 'http://localhost:8000/cart'
}
},
computed:{
}
}
</script>
なぜあなたは 'computed'と' updated'フックの両方から 'getCartItems'を呼び出していますか? – Saurabh
あなたは私が言うと「マウントされた」という意味です。 'mounted'のものが最初のカートアイテムを取得しようとしています。 'カート'のデータがプロジェクトのどこかで変更された場合(更新数量など) – warmjaijai
はい、私は 'マウントされた 'ことを意味しました。おそらく他の戦略を見つけたり、双方向を使用したりする必要がありますデータの変更にもvueをバインドします。 – Saurabh