在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ iview-ui JSX綁定click事件報錯

iview-ui JSX綁定click事件報錯

問題描述

使用iview-ui的Table組件,通過JSX渲染表格的操作列,但是綁定按鈕點擊事件時,報錯:
vue.esm.js?efeb:591 [Vue warn]: Invalid handler for event "click": got undefined

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

  • 項目.babelrc已經(jīng)配置好JSX的支持,組件都能渲染出來
  • 查詢Vue官方文檔和JSX的Git文檔說明,確認事件綁定是沒問題的

https://cn.vuejs.org/v2/guide...
https://www.cnblogs.com/wenst...
https://github.com/vuejs/babe...

相關(guān)代碼

  • vue組件
<template>
    <div>
        <div>
            <h4 class="font-weight-bold py-3 mb-4">數(shù)據(jù)源管理</h4>
            <p> This page is an example of basic layout. For more options use
                <strong>Vue starter template generator</strong> in the docs.</p>
        </div>
        <b-card header="數(shù)據(jù)源列表" header-tag="h6" class="mb-4">
            <Table stripe border :columns="table.columns" :data="table.dataList"></Table>
        </b-card>
    </div>
</template>

<script>
import iView from 'iview'
Vue.use(iView)

export default {
    name: "ReportIndex",
    data() {
        return {
            table: {
                showIndex: false,
                dataList: [
                    {
                        origin_name: "企查查",
                        quota: 1000,
                        total: 99999
                    },
                    {
                        origin_name: "工商信息查詢",
                        quota: 1000,
                        total: 99999
                    },
                    {
                        origin_name: "征信數(shù)據(jù)查詢",
                        quota: 1000,
                        total: 99999
                    }
                ],
                columns: [
                    {
                        title: "數(shù)據(jù)源",
                        key: "origin_name"
                    },
                    {
                        title: "調(diào)用配額",
                        key: "quota"
                    },
                    {
                        title: "累積調(diào)用次數(shù)",
                        key: "total"
                    },
                    {
                        title: "操作",
                        render (h) {
                            return (
                                <div>
                                    <i-button type="primary" size="small" class="mr-2" on-click={this.goConsole}>查看詳情</i-button>
                                    <i-switch>
                                        <span slot="open">開</span>
                                        <span slot="close">關(guān)</span>
                                    </i-switch>
                                </div>
                            )
                        }
                    }
                ]
            }
        };
    },
    created() {},
    methods:{
        goConsole: function(){
            console.log(123)
        }
    }
};
</script>

你期待的結(jié)果是什么?實際看到的錯誤信息又是什么?

圖片描述

回答
編輯回答
尐懶貓

你好,看了下你的代碼,發(fā)了2個問題。
1、是你的this指向問題。 你這里的this指向的是row內(nèi)容而不是vue的實例,所以請?zhí)鎿Q為箭頭函數(shù),這樣this可以指向vue的實例。
2、jsx對應(yīng)vue事件綁定的用法。你參照官網(wǎng)綁定事件請使用onClick而不是on-click。
第二點在你發(fā)給我的鏈接中有寫

clipboard.png

下面貼上代碼 你可以測試下。

              render:(h) =>{
                console.log(this)
                return (
             <div>
                    < i-button type="primary" size="small" class="mr-2" onClick={this.goConsole}>
                      查看詳情
                    </i-button>
                    < i-switch>
                      <span slot="open"> 開 </span>
                      < span slot="close"> 關(guān) </span>
                    </i-switch>
                  </div>
                )
              }
結(jié)束語:如果解決問題了,請點下采納,如果再點下贊的話 更好了 哈哈
2018年1月31日 12:59