vue calls $notify in js file

In the vue component we can directly

this.$notify({
    
    
	title: '修改成功',
	type: 'success',
	duration: 2500
})

But in js, our this point will be different
. In fact, people who have learned constructors and prototype chains will understand this very well.
Each vue component is an instance constructed through vue,
so their this points to The current instance object
, and when they can't get something, they will go to the higher level to get it and finally get it to vue,
but the highest level pointed to in js is the window object.

Then we just want to get it directly from vue

import Vue from 'vue';
Vue.prototype.$notify({
    
    
	title: '访问的资源不存在,请联系管理员',
	type: 'error',
	duration: 2500
})

We can directly introduce the vue instance
and then call it through the prototype chain of the instance object.

The running results are as follows
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/133014882