0
當我編輯帖子時,我使用vue js傳遞選定多個選項的值。 我使用元素UI來選擇選項。如何在不使用v-for vue js的情況下調用所選多個項目選項的ID?
PostController中
return Post::with('category')->with('tag')->find($id);
Post.vue
<el-select v-model="form.tag_id" multiple placeholder="Select some">
<el-option v-for="tag in tags" :key="tag.id" :label="tag.name"
:value="tag.id">
</el-option>
</el-select>
<script>
data() {
return {
tags: [],
form: new Form({
tag: [],
tag_id: [],
}),
}
// fetch all tags list
axios.get('/' + this.$route.params.trans + '/adminGetTags')
.then(({data}) => this.tags = data)
//fetch post and tag which related to post
axios.get('/' + this.$route.params.trans + '/editPost/' +
this.$route.params.id)
.then(({data}) => {
//....
this.form.tag = data.tag
this.form.tag_id = data.tag
})
</script>
我需要調用選擇多個項目的id這樣
this.form.tag_id = data.tag.id
BUIT它會給出一個錯誤(無法讀取財產'長度'未定義)
但是,如果我使用v-它會工作,不幸的是我不能在選擇標籤中使用v-model和v-for。任何想法如何解決這個問題?
你試過'this.form.tag_id = [data.tag.id]'如果我記得沒錯VUE將檢測'multiple'指令,並設置期望類型的數組 –
賈斯汀,它不工作。拋出一個錯誤'[Vue警告]:子項必須被鍵入:'。但是,如果我將el-select更改爲正常的多選,它不會給任何東西。沒有錯誤,它是空的。 –
lolagi
檢查您的data.tag.id.在element.io https://jsfiddle.net/deepaksingh/fpjaqcfn/ – Deepak