Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind to attribute in Vue JS?

Tags:

vue.js

I got this error

Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.

on this line

<a href="/Library/@Model.Username/{{myVueData.Id}}">

It works in Angular 1. How do you do it in Vue?

like image 204
Aximili Avatar asked Mar 28 '17 06:03

Aximili


1 Answers

In your template:

<a :href="href">

And you put href in data:

new Vue({
  // ...
  data: {
    href: 'your link'
  }
})

Or use a computed property:

new Vue({
  // ...
  computed: {
    href () {
      return '/foo' + this.someValue + '/bar'
    }
  }
})
like image 151
CodinCat Avatar answered Oct 01 '22 09:10

CodinCat