从 handsontable 访问 vue 实例
Access vue instance from handsontable
我正在尝试从 handsontable 中设置一个 vuejs 变量。
vuejs变量:
this.dataChanged
下面的代码块中的 handsontable 设置不可用,知道如何访问它吗?
<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
}
}
}
我最终保存到一个在 vue 之外声明的变量——即在数据 () 声明之上
var myNewVar = 42
data() {
#can save to myNewVar from here
我遇到了同样的问题...我在 GitHub 上找到了一个解决方法,就像这样...
这样您就可以像往常一样访问 Vue 的所有数据、方法等。
data() {
return {
hotSettings: {
...
afterChange: this.afterChangeVue
...
}
}
},
methods: {
afterChangeVue(changes, source) {
console.log('changes, source => ', changes, source);
console.log('this.$store => ', this.$store);
},
这里是 link 原线程:https://github.com/handsontable/vue-handsontable-official/issues/7#issuecomment-356190395
我正在尝试从 handsontable 中设置一个 vuejs 变量。
vuejs变量:
this.dataChanged
下面的代码块中的 handsontable 设置不可用,知道如何访问它吗?
<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
}
}
}
我最终保存到一个在 vue 之外声明的变量——即在数据 () 声明之上
var myNewVar = 42
data() {
#can save to myNewVar from here
我遇到了同样的问题...我在 GitHub 上找到了一个解决方法,就像这样...
这样您就可以像往常一样访问 Vue 的所有数据、方法等。
data() {
return {
hotSettings: {
...
afterChange: this.afterChangeVue
...
}
}
},
methods: {
afterChangeVue(changes, source) {
console.log('changes, source => ', changes, source);
console.log('this.$store => ', this.$store);
},
这里是 link 原线程:https://github.com/handsontable/vue-handsontable-official/issues/7#issuecomment-356190395