代码之家  ›  专栏  ›  技术社区  ›  proximacentauri

从handsontable访问vue实例

  •  1
  • proximacentauri  · 技术社区  · 7 年前

    我正在尝试从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
        }
      }
    }
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Rosdi Kasim    6 年前

    我也面临同样的问题。。。我在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

        2
  •  0
  •   proximacentauri    7 年前

    最后,我保存到一个在vue之外声明的变量,即data()声明上方的变量

    var myNewVar = 42
    data() {
        #can save to myNewVar from here