[Vuejs]-How to get bind value in vue js?

2👍

you can pass variable in method called on click

like this:
<a href="#" @click="getTitle(model)">View Detail</a>

and then in method:

getTitle:function(model) {
console.log(model);
}

1👍

You can just do:

<div id="app">
  <div v-for="model in myData">
    <h1>{{model.title}}</h1>
    <p>{{model.project}}</p>
    <p>{{model.bedrooms}}</p>
    <a href="#" @click="getTitle(model)">View Detail</a>
  </div>
</div>

var vm = new Vue({
  el:'#app',
  data(){
    return {
      myData:[]
    }
  },
  created () {
    this.fetchData();
  },
  methods:{
    fetchData () {
      let vm = this;
      var url='data.json';
      axios.get(url)
       .then(function(res){
         vm.myData = res.data.models;
         console.log(vm.myData);
       });
    },
    getTitle (model) {
      console.log(model.title)
    }
  }
});

Just change some of your code. You can take model as parameter in getTitle function. You dont have to call it in mounted hook

Leave a comment