1
我有一個Vue組件,我使用internalValue
來訪問value屬性。我如何擴展這個也得到ID
?在組件中擴展Vue函數以顯示ID
即internalValue = value, id
我都試過,但我不知道如何添加這個功能internalValue裏面。我甚至試圖通過將所有值的實例更改爲id來獲取ID,但它仍然吐出值。
我很樂意讓他們成爲一個即value, id
或訪問他們像data.value
和data.id
初始化Vue公司
new Vue({
el: '#topic',
data: {
selectedTopic: null
}
});
使用組件
<div class="form-group" id="topic">
<topic v-model="selectedTopic"></topic>
</div>
註冊組件
Vue.component('topic', require('./components/Topicselect.vue'));
組件
<template>
<div>
<label v-for="topic in topics" class="radio-inline radio-thumbnail">
<input type="radio" v-model="internalValue" name="topics_radio" :id="topic.id" :value="topic.name">
<span class="white-color lg-text font-regular text-center text-capitalize">{{ topic.name }}</span>
</label>
<ul class="hidden">
<li>{{ internalValue }}</li>
</ul>
</div>
</template>
<script>
export default {
props: ['value'],
data() {
return {
internalValue: this.value,
topics: []
}
},
mounted(){
axios.get('/vuetopics').then(response => this.topics = response.data);
},
watch: {
internalValue(v){
this.$emit('input', v);
console.log('Topicselect: the value is ' + this.internalValue);
}
}
}
</script>
謝謝你,這是魔術在那裏:) –
@ClintonGreen不客氣:)我在改變後的模板編輯,特別是':檢查=「值&& topic.id == value.id」'在某些時候你開始使用一個值而不是null。 – Bert
呀一日2次,我得到了ID =零錯誤,但我看到的編輯。感謝堆。 –