3

I have some vue.js components, all these components get their data from outside.

Example:

<vue-button icon="fa-arrow-right" text="mytext"></vue-button>

This works great so far but now I have to set multiple values over the property.

This does not work:

<vue-list items="['Entry1', 'Entry2']"></vue-list>

How can I set multiple values over one property?


Update

I have a working example but I am not sure if thats the right way to go but it works. If someone knows a better way I would be happy if you share it with me/us.

This is how I call the component:

<vue-list times='[ "08:00 - 12:00", "13:00 - 21:00" ]'></vue-list>

And this is the code of the component:

<template>
    <div>
        <div v-for="item in timesArray">
            <span v-html="item"></span>
        </div>
    </div>
</template>

<script>
export default {
    props: ['times'],
    data: function() {
        return {
            timesArray: [],
        }
    },
    created: function() {
        this.timesArray = JSON.parse(this.times);
    }
}
</script>
1
  • Just use :items or v-bind:items. Commented Mar 5, 2017 at 16:09

3 Answers 3

3

Use the attribute binding syntax.

<vue-list :times='[ "08:00 - 12:00", "13:00 - 21:00" ]'></vue-list>

Note the colon in front of :times. You don't need to parse or use data.

Sign up to request clarification or add additional context in comments.

Comments

0

It is not because you missed to close the Entry 2 string?

<vue-list items="['Entry1', 'Entry2]"></vue-list>

The right code is

<vue-list items="['Entry1', 'Entry2']"></vue-list>

Think it should work if the component logic is okay.

1 Comment

No sorry, thanks for the correction. It was just a typo here on stackoverflow. It always comes as a string to the component not as an array.
0

You have to pass it using an vue instance variable only, see this fiddle.

<div id="app">
  <child  :items="items"></child>
</div>

where items in defined as vue instance data:

new Vue({
  el: '#app',
  data: {
    full_name: "Initial Val",
    items: ['Entry1', 'Entry2']
  }
})

1 Comment

But if I use data I cant set it from outside as property.

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.