vuejs pu sh теги отдельно для ввода - PullRequest
0 голосов
/ 24 февраля 2020

У меня есть входные теги, данные которых разделены запятыми (,), и на странице редактирования я хотел бы показать каждый из них по отдельности. (отдельно от запятой) '

Образец

data

here, goes, testing,tags,check,this,out

current result

onw

What I want it to be

two

Код

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);
            });
        },
    }
}

1 Ответ

2 голосов
/ 24 февраля 2020

Попробуйте разделить данные, используя разбивку строк, затем нажмите получившийся массив элементов:

this.form.tags.push(...response.data.seo.tags.split(','))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...