Echarts3之后的版本事件绑定的函数书写如下:
this.myChart.on("click", function (params) {
var url = "/";
console.log(this.$router)
this.$router.push(url);
});
这里汇报错,在控制台中查看日志可知:this.$router属性为undefined。
这里是由于创建一个函数之后this的对象已经不再指向vue了。
所以我们利用回调函数来进行书写。
this.myChart.on("click", (params) => {
// 这里必须要使用回调函数
var url = "/";
console.log(this.$router);
this.$router.push(url);
});
可以看到这样就可以正常跳转页面了,并且输出了this.$router对象。