antdv 报错 ReferenceError: h is not defined

源代码如下

<template>
  <div class="notice-table">
    <a-table
      :columns="columns"
      :data-source="list"
      size="middle"
      :pagination="{
        pageSize: 10
      }"
      :customRow="rowClick"
    >
      <template slot="OID" slot-scope="index">
        <a>{{ index }}</a>
      </template>
      <!-- <router-link :to="{ name: 'notice-detail' }" slot="name" slot-scope="text">{{ text }}</router-link> -->
    </a-table>
  </div>
</template>

<script>
const columns = [
  {
    title: "序号",
    dataIndex: "OID",
    customRender: (text, row, index) => { 
      return <a href="javascript:;">{index}</a>;
    }
  },
  {
    title: "标题",
    dataIndex: "TOPIC"
  },
  {
    title: "发布日期",
    dataIndex: "ISSUEDATE"
  }
];

export default {
  props: {
    list: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      columns
    };
  },
  methods: {
    rowClick() {
      return {
        on: {
          click: () => {}
        }
      };
    }
  },
  mounted() {
    console.log(this.$props);
  }
};
</script>

<style lang="less">
.notice-table .ant-pagination {
  width: 100%;
  margin: 16px auto;
  text-align: center;
}
</style>

后来改为这样:

<template>
  <div class="notice-table">
    <a-table
      :columns="columns"
      :data-source="list"
      size="middle"
      :pagination="{
        pageSize: 10
      }"
      :customRow="rowClick"
    >
      <template slot="OID" slot-scope="index">
        <a>{{ index }}</a>
      </template>
      <!-- <router-link :to="{ name: 'notice-detail' }" slot="name" slot-scope="text">{{ text }}</router-link> -->
    </a-table>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true
    }
  },
  data() {
  	// 改动位置 columns 
    const columns = [
      {
        title: "序号",
        dataIndex: "OID",
        customRender: (text, row, index) => {
          return <span>{index + 1}</span>
        }
      },
      {
        title: "标题",
        dataIndex: "TOPIC"
      },
      {
        title: "发布日期",
        dataIndex: "ISSUEDATE"
      }
    ];
    return {
      columns
    };
  },
  methods: {
    rowClick() {
      return {
        on: {
          click: () => {}
        }
      };
    }
  }
};
</script>

<style lang="less">
.notice-table .ant-pagination {
  width: 100%;
  margin: 16px auto;
  text-align: center;
}
</style>

原因分析是data初始化时并未将表格的表头部分渲染出来,导致vue的template渲染函数出错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中提到的解决方法是在vue.config.js中添加一些配置,其中使用了webpack的ProvidePlugin插件来提供全局的jquery变量。这样就能解决报错"ReferenceError: $ is not defined"的问题。中提到的报错提示不是由于没有使用lib:["dom"]造成的,而是在类型注释中使用了MouseEvent。在这种情况下,没有问题的。中指出,如果项目中引用了.eslintrc.js文件,还需要在文件的module.exports中为env添加一个键值对jquery: true,然后重新启动项目。这样也可以解决报错"ReferenceError: $ is not defined"的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue引入JQuery报错caught ReferenceError: jQuery is not defined](https://blog.csdn.net/qq_46034741/article/details/130032090)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [vue ssr 报错 ReferenceError: MouseEvent is not defined / window is not defined 等等](https://blog.csdn.net/qq_28550263/article/details/130152398)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Vue小知识: $ is not defined错误解决](https://blog.csdn.net/weixin_43945983/article/details/88294052)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值