我试图从handontable中设置一个vuejs变量。
vuejs变量:
this.dataChanged
在下面的代码块中无法通过双手设置获得,任何想法如何访问它?
<template>
<div id="hot-container">
<HotTable :root="root" :settings="hotSettings"></HotTable>
</div>
</template>
<script>
export default {
data() {
return {
#vuejs variable i want to set from hot
dataChanged: false,
root: 'test-hot',
hotSettings: {
data: [{something: 0}],
afterChange: function(changes, src) {
if (src !== 'loadData') {
this.dataChanged = true
}
},
methods: {
saveChanges: function () {
if (this.dataChanged){
//save data
}
}
}
我遇到了同样的问题......我在GitHub上发现了一个解决方法,就像这样......
这样您就可以像平常一样访问所有Vue的数据,方法等。
data() {
return {
hotSettings: {
...
afterChange: this.afterChangeVue
...
}
}
},
methods: {
afterChangeVue(changes, source) {
console.log('changes, source => ', changes, source);
console.log('this.$store => ', this.$store);
},
这是原始主题的链接:https://github.com/handsontable/vue-handsontable-official/issues/7#issuecomment-356190395
我最终保存到在vue之外声明的变量 - 即在data()声明之上
var myNewVar = 42
data() {
#can save to myNewVar from here