- app.component("child", {
- props: ["count"],
- methods: {
- handleClick() {
- console.log("test");
- },
- },
- render() {
- const { h } = Vue;
- return h(
- "div",
- {
- on: {
- click: this.handleClick,
- },
- style: {
- cursor: "pointer",
- },
- },
- " count: " + this.count
- );
- },
- });
代码如上,我想使用render函数创建一个组件模板,并且给该组件绑定一个点击事件,为什么不能成功?应该怎么写,上面是我百度的写法。可这写法写上去,只是让html代码多一个on的属性,和事件没什么关系。
<div on="[object Object]" test="test" style="cursor: pointer;"> count: 1</div>