admin管理员组

文章数量:1356582

I'm using bootstrap-date-picker with Vue.js 2. Bootstrap datepicker doesn't update the model.

But if I use the following script, I cannot access the scope to use this

loadFormProps() {
// init other stuff
$('#founding_date').change(function() {
  this.founding_date = $(this).val();
});
}

Modal is as following:

data() {
  return {
    founding_date: '01 - 01 - 2017',
  }
};

What will be the best solution for this, as I cannot get vm.$data working, and I cannot access this within the function.

I'm using bootstrap-date-picker with Vue.js 2. Bootstrap datepicker doesn't update the model.

But if I use the following script, I cannot access the scope to use this

loadFormProps() {
// init other stuff
$('#founding_date').change(function() {
  this.founding_date = $(this).val();
});
}

Modal is as following:

data() {
  return {
    founding_date: '01 - 01 - 2017',
  }
};

What will be the best solution for this, as I cannot get vm.$data working, and I cannot access this within the function.

Share Improve this question edited May 23, 2017 at 12:02 CommunityBot 11 silver badge asked Jan 23, 2017 at 10:56 MapDevMapDev 1051 silver badge8 bronze badges 1
  • You have two this inside the change callback function. Which this is not accessible? What is the console error message? What should the first this refer to? – gus27 Commented Jan 23, 2017 at 11:06
Add a ment  | 

1 Answer 1

Reset to default 8

You have to save the this inside some other var before the onchange JS block:

loadFormProps() {
// init other stuff
var that = this  
$('#founding_date').change(function() {
  that.founding_date = $(this).val();
});
}

本文标签: javascriptUpdate data value with Vue from jQuery onChangeStack Overflow