javascript - Vue.js template concatenate props -




js:

vue.component('profile', {     template: `<a v-bind:href="id"></a>`,      props: ['id'] });  var app = new vue({     el: '.app',     data: {         user: userobject     } }); 

html:

<profile :id="user.id"></profile> 

expected result:

<a href="/profile/2"> 

question: how concatenate "/profile/" user.id equal 2?

you can write javascript inline in vue templates this:

template: `<a v-bind:href="'/profile/' + id"></a>`, 

alternately, bind computed property:

vue.component('profile', {   template: `<a v-bind:href="url"></a>`,   props: ['id'],   computed: {     url() {       return '/profile/' + this.id;     }   } }); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -