通过在VueJS中单击,在setter的帮助下更改计算属性

时间:2018-11-21 09:00:29

标签: javascript vue.js vuejs2

我的模版中有一个模态

<loading-modal:modal-state="openAddProductsModal.state"  title="Add New Products" size="lg" >
     <add-product  ref="addProduct" :@has-errors="openAddProductsModal.errors = $event" :"/>
       <div slot="footer">
         <btn  @click="$set(openAddProductsModal, state, false)">Cancel</btn>
           <btn :disabled="openAddProductsModal.errorAdd " type="primary" @click="save()">
           Save
         </btn>
       </div>
</loading-modal>

我也有这样的计算属性:

computed: {
   openAddProductsModal: {
     get() {
       this.errorAdd = true;
       return {state: this.$route.query.modal == 'open', errors: this.errorAdd}
     },
     set(newValue) {
       this.errorAdd = newValue.errors
       ModalState.setModalState(newValue.state, this.$route, this.$router, 'open')
     }
   },
}

我想通过单击属性Cancel上的按钮state进行更改,但似乎不起作用-我也尝试过使用this.$set。如何通过单击按钮来调用setter方法?

0 个答案:

没有答案