1

I'm using VueJS to create a tab system, every tab having it's own set of properties, so I created a list of objects containing those properties, and now I want to get these properties in my vue.

This is the vue inside my component:

<div>
    <large-card v-bind:path="tabs[currentTab].path"></large-card>
</div>

And this is the Js Vue component (I got rid of the irrelevant code):

export default {
    data () {
        return ({
            tabs: [
                {
                    name: 'Nodes',
                    path: '/nodes/'
                },
                {
                    name: 'Sensors',
                    path: '/sensors/'
                }
            ],
            currentTab: 0
        });
    }
}

As you can see, I want to pass the path value of the current tab to my component, so in this example it should get the value '/nodes/', but it doesn't work this way. I knew a way to do it in Angular, exposing the object as "this" into the scope of a HTML tab, but I don't remember the directive's name...

Thank you for your attention, have a nice day!

2
  • 1
    Do you get an error? What do you mean by "it doesn't work this way"? Because everything seems fine... Commented Mar 8, 2018 at 21:02
  • Sorry, I meant the value I get is undefined Commented Mar 9, 2018 at 14:04

1 Answer 1

1

You can use a computed property for this.

computed: {
    path(){
        return this.tabs[this.currentTab].path;
    }
 },

Then bind the path to a path prop and pass it to your other child

<large-card v-bind:path="path" ></large-card>

Here is a jfiddle you can test it in https://jsfiddle.net/skribe/xvwvx2b7/1/

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.