用户点击链接元素:
户点击链接交互,即点击了 <router-link>
props: { tag: { type: String, default: 'a' }, // 绑定的事件 event: { type: eventTypes, default: 'click' } }, render (h: Function) { const handler = e => { if (guardEvent(e)) { if (this.replace) { router.replace(location) } else { router.push(location) } } } const on = { click: guardEvent } if (Array.isArray(this.event)) { this.event.forEach(e => { on[e] = handler }) } else { // 事件绑定处理函数 on[this.event] = handler } return h(this.tag, data, this.$slots.default) }
该组件主要是通过render
函数,默认创建一个a
标签,同时为标签绑定click
事件