我有标签输入,其中的数据是由逗号(,)分隔的,在编辑页面中,我想将它们分别显示出来。(基于逗号分隔)‘
示例
data
here, goes, testing,tags,check,this,out
current result
What I want it to be
代码
fetchData() {
axios
.get('/api/admin/settings/'+this.$route.params.id, {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('access_token')
}
})
.then(response => {
this.form.tags.push(response.data.seo.tags) // here is my data returning to input (image #1)
})
.catch(function (error) {
console.log('error', error);
});
},
有什么想法吗?
更新
html
<el-form-item label="SEO Tags">
<el-select
style="width:100%"
v-model="form.tags"
multiple
filterable
allow-create
default-first-option
placeholder="Please input your seo tags (type + hit enter)">
</el-select>
</el-form-item>
script
export default {
data() {
return {
dialogImageUrl: '',
dialogVisible: false,
site_url: process.env.MIX_APP_URL,
form: {
name: '',
tagline: '',
logo: '',
favicon: '',
title: '',
tags: [],
description: '',
photo: '',
_method: 'PUT',
},
}
},
created () {
this.fetchData()
},
methods: {
fetchData() {
axios
.get('/api/admin/settings/'+this.$route.params.id, {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('access_token')
}
})
.then(response => {
this.form.tags.push(response.data.seo.tags) // here is my data returning to input (image #1)
})
.catch(function (error) {
console.log('error', error);
});
},
}
}
发布于 2020-02-24 01:35:17
尝试使用string split拆分数据,然后推送生成的项目数组:
this.form.tags.push(...response.data.seo.tags.split(','))
https://stackoverflow.com/questions/60368467
复制相似问题