首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >vuejs单独推送标签到input

vuejs单独推送标签到input
EN

Stack Overflow用户
提问于 2020-02-24 09:20:56
回答 1查看 112关注 0票数 0

我有标签输入,其中的数据是由逗号(,)分隔的,在编辑页面中,我想将它们分别显示出来。(基于逗号分隔)‘

示例

data

代码语言:javascript
运行
复制
here, goes, testing,tags,check,this,out

current result

What I want it to be

代码

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
<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

代码语言:javascript
运行
复制
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);
            });
        },
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-24 09:35:17

尝试使用string split拆分数据,然后推送生成的项目数组:

代码语言:javascript
运行
复制
this.form.tags.push(...response.data.seo.tags.split(','))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60368467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档