A method frequently used, I do not want to introduce every time, with the introduction of a Plugin, and more calls, Bang Bang da
1. Create Method
-
src
Under the newplugin
folder, used to store plug-ins - For example, I want to call the method named
$toTop
, the newtoTop.js
, the preparation method (global best way to start with $)
export default {
install (Vue, options) {
Vue.prototype.$toTop = function () {
console.log('Plugin Test')
}
}
}
2. Add a Vue
global approach
- In
main.js
the introduction, add
// 插件
import ToTop from './plugin/toTop' // 引入
Vue.use(ToTop) // 添加
3. Use
- Then you can freely use it in the assembly
mounted () {
this.$toTop()
}