Кнопки не работают с помощью табулятора в VueJs - PullRequest
0 голосов
/ 31 марта 2020

Здесь я настроил таблицу с помощью табулятора в моем проекте VueJs. Я следовал инструкциям по настройке табулятора в VueJs из: http://tabulator.info/docs/4.1/frameworks#vue. Я добавил кнопку, например, добавление строки и обновление строки, но по какой-то причине она не работает. Я вижу свою кнопку, но она не работает.

Вот мой код:

 <template>
<div class="table-wrapper">
    <div ref="table">
    </div>
    <v-btn color="green" @click="addRow">Add Row</v-btn>

</div>


</template>

 <script>
    var Tabulator = require('tabulator-tables')
    export default {
      name: 'Location',
      data: function () {
        return {
          tabulator: null, // variable to hold your table
          location: [] // data for table to display
        }
      },
      watch: {
        // update table if data changes
        location: {
          handler: function (newData) {
            this.tabulator.replaceData(newData)
          },
          deep: true
        }
      },
      created: function () {
        console.log('Location', this.$refs)
        this.initialize()
      },
       methods: {
       initialize () {
          axios.get('/api/location')
        .then(response => this.location =  response.data.location)

        },

         addRow() {
        // add your row here
        this.location.addRow({})
    }
       },
      mounted () {
        // instantiate Tabulator when element is mounted
        this.tabulator = new Tabulator(this.$refs.table, {
          data: this.location,
          layout:"fitDataStretch",   
          movableColumns:true,
          addRowPos:"bottom",
           // link data to table
          columns: [
            {title: 'Code', field: 'code', sorter: 'string',width: 100,  editor: 'input' , validator: "required"},
            {title: 'Name', field: 'name', sorter: 'string', width: 200 , validator: "required",editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
            {title: 'Under', field: 'under', sorter: 'string', width: 200,  editor: 'input' , validator: "required"},
            {title: 'Status', field: 'status', sorter: 'string',width: 100,  editor: 'input' , validator: "required"},
            {title: 'Description', field: 'description', sorter: 'string', width: 200,  editor: 'input' , validator: "required"},
            {title: 'Depth', field: 'depth', sorter: 'string', width: 100,  editor: 'input' , validator: "required"}

          ]
        });




      },

    }
    </script>
<style scoped>

</style>

1 Ответ

0 голосов
/ 31 марта 2020

Не стоит использовать jQuery и Vue. js в одном интерфейсе. Не делайте этого, если можете этого избежать.

Ваши кнопки не привязаны к каким-либо функциям или действиям Vue.

Просто используйте привязку событий к кнопкам, прикрепляя это один из ваших методов, чтобы контролировать то, что он делает, например:

<v-btn color="green" @click="addRow">Add Row</v-btn>

, а затем методы вашего компонента:

methods: {
    addRow() {
        // add your row here
        this.location.addRow({})
    }
}
...