1

I have tags input which the data are separated by commas (,) and in edit page i'd like to show each of them separably. (separate based on comma's)'

Sample

data

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

current result

onw

What I want it to be

two

Code

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

any idea?

Update

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);
            });
        },
    }
}
6
  • What string function in JavaScript allows you to split a string based on some separator? Then what array operation allows you to combine two different arrays? What have you tried other the code above? Commented Feb 24, 2020 at 1:26
  • @AlexanderStaroselsky must of your questions i didn't understand but i'll update my question with more detail give me a min please Commented Feb 24, 2020 at 1:28
  • You can split a string using developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… . You can combine two arrays using concat developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… . Try using those two methods to solve your issue. Commented Feb 24, 2020 at 1:30
  • @AlexanderStaroselsky updated. also is not 2 arrays is only 1 array nothing to combine just splitting the result Commented Feb 24, 2020 at 1:31
  • If you split the string it becomes an array. Then it looks like data form tags is an array. So that would make two arrays. Commented Feb 24, 2020 at 1:32

1 Answer 1

2

Try splitting the data using string split then pushing the resulting array of items:

this.form.tags.push(...response.data.seo.tags.split(','))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.