选择元素更改后,Vue.js不会重新渲染

时间:2018-03-09 16:54:50

标签: javascript vue.js

使用Vue.js。

我有两个对象数组,categorycategoryParcategory包含名称和父级的名称,categoryPar只包含名称。我想只显示属于选定父级的类别。试着这样做:

<select v-model="editing.categoryPar"">
       <option v-for="cat in categoryPar" v-bind:value="cat.name">{{ cat.description }}</option>
</select>
<select v-model="editing.category">
       <option v-for="cat in category" v-if="editing.categoryPar == cat.par_name" v-bind:value="cat.name">{{ cat.description }}</option>
</select>

条件已履行但未重新渲染。当我在console vue中使用时。$ forceUpdate();然后它工作,直到我改变父选择。

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您需要先创建所选模型的变量。

目前,您正在为function mathCheck() { var inputValues1 = document.mathGuesser.mGuesser.value; var attempts; for (attempts = 3; attempts >= 0; ) { if (inputValues1 === 'y = 2x - 3' || inputValues1 === 'y=2x-3') { document.getElementById("answer").style.color = "Green"; document.getElementById("answer").innerHTML = "<span>" + "Correct" + "</span>"; } else if (inputValues1 === ' ' || inputValues1 === '') { document.getElementById("answer").style.color = "Black"; document.getElementById("answer").innerHTML = "<span>" + "Please enter text" + "</span>"; } else { document.getElementById("answer").style.color = "Red"; document.getElementById("answer").innerHTML = "<span>" + "Incorrect" + "</span>"; document.getElementById("attempts").innerHTML = attempts; attempts--; } } document.getElementById("answer").style.color = "Black"; document.getElementById("answer").innerHTML = "No attempts left"; } 提供一个对象,这就是它无效的原因

v-model
new Vue({
  el: '#app',

  data () {
    return {
      selectedCategory:  '', 
      category: [{name: 'A', parent: 'Alpha'}, {name: 'B', parent: 'Bravo'}, {name: 'C', parent: 'Charlie'}],
      categoryPar: [{name: 'A'}, {name: 'B'}, {name: 'C'}],
    }
  },
})