我在表單中有一個vue multiselect的vue組件。我希望禁用/啓用此功能,直到填寫了其他兩個字段。從Vue組件中的總線值獲取布爾值
我已經通過總線值在組件內部訪問了該數據,但是當我嘗試使用它時,我從未得到如預期的真或假回答。
我試圖更新disabled
屬性與enableKeywords
這是由selectedTopic && questionTitle
控制,這兩個值都從根或其他部件上,我可以看到在通過Vue公司開發工具組件的根他們的數據進行更新。
複選元器件
<template>
<div>
<multiselect
v-model="internalValue" tag-placeholder="Add this as new tag" placeholder="Search"
label="name" track-by="id" :options="options" :multiple="true" :disabled="enableKeywords">
</multiselect>
</div>
</template>
<script>
import Multiselect from 'vue-multiselect'
export default {
components: { Multiselect },
props: ['value'],
data() {
return {
internalValue: this.value,
options: [],
selectedTopic: null,
questionTitle: null,
enableKeywords: selectedTopic && questionTitle
}
},
mounted(){
axios.get('/vuekeywords').then(response => this.options = response.data);
bus.$on("send-topic", selectedTopic => this.selectedTopic = selectedTopic);
bus.$on("send-title", questionTitle => this.questionTitle = questionTitle);
},
watch: {
internalValue(v){
bus.$emit('send-keywords', v);
this.$emit('input', v);
}
}
}
</script>
我認爲這將只是':禁用=' – Bert
太感謝了,這就是我認爲這將是,但我有錯誤的語法「(selectedTopic && questionTitle)!」。我沒有意識到它需要用括號包裝。請添加爲答案,我會接受。乾杯 –