search

Home  >  Q&A  >  body text

javascript - vue component data loop

vue component, cuts the string into an array and then loops the output results and reports an error

I want to get the following data

#1岁-2岁 #breakfast #快手

var test = "1 year old-2 years old, breakfast, fast hand";

<cook-tag :tags="test" />

Vue.component("cook-tag", {
    template: "<span class='tag-item' v-for='item in list'>#{{item}}</span>",
    data() {
        return {
            list:[],
        }
    },
    props: ["tags"],
    created(){
        this.list = this.tags.split(",") || [];
    },
})
天蓬老师天蓬老师2832 days ago652

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-18 11:04:33

    Component template can only have one parent element, and span needs to be wrapped

    reply
    0
  • Cancelreply