0

How to inject component data in <router-link to="...">? Sample:

var data = {files: [{name: "test", path: "/test"}]};

var component = {
    data: function() {
        return data
    },
    template: '<ul class="files"><li v-for="file in files"><router-link to="{{ file.path }}">{{ file.name }}</router-link></li></ul>',
    created: function() {...}
};

In this sample the output is <li><a href="#/{{ file.path }} ">test</a></li>. How do I get /test instead of #/{{ file.path }}?

1

1 Answer 1

1

You are using wrong syntax, You just need to use v-bind as follows:

template: '<ul class="files"><li v-for="file in files"><router-link v-bind:to="file.path">{{ file.name }}</router-link></li></ul>',

or in short:

template: '<ul class="files"><li v-for="file in files"><router-link :to="file.path">{{ file.name }}</router-link></li></ul>',
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.