簡體   English   中英

如何使用vue tables 2(JSX)綁定vue click事件?

[英]How to bind vue click event with vue tables 2 (JSX)?

使用https://github.com/matfish2/vue-tables-2 ,使用Vue版本2,我似乎無法綁定JSX上的click事件(在templates-> edit上):

var tableColumns = ['name', 'stock', 'sku', 'price', 'created_at']
var options = {
  compileTemplates: true,
  highlightMatches: true,
  pagination: {
    dropdown: true,
    chunk: 10
  },
  filterByColumn: true,
  texts: {
    filter: 'Search:'
  },
  datepickerOptions: {
    showDropdowns: true
  },
  templates: {
    edit: function (h, row) {
      return <button v-on:click={this.showItem(row.id)} class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
    },
    delete: function (h, row) {
      return <a href="javascript:void(0);" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-erase"></i></a>
    }
  }
}

export default {
  name: 'ItemList',
  data: function () {
    return {
      options: options,
      columns: tableColumns
    }
  },
  methods: {
    showItem: function (id) {
      console.log(id)
    }
  }
}

on-click更改為JSX,但Vue無法識別。 .babelrc已經有:

{
    "presets": ["es2015"],
  "plugins": [
    "transform-runtime",
    "transform-vue-jsx"
  ]
}

我很難學到這一點,因為我在尋找解決方案時並不熟悉JSX。 但是,不要使用onClick ,而是單擊鼠標右鍵

干得好:

ES6

edit: (h, row) => {
  return <button on-click={ () => this.showItem(row) } class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
},

ES5:

edit: function (h, row) {
  return <button on-click={ this.showItem.bind(this, row) } class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM