| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import {
- setStorage,
- getStorage,
- prePage
- } from "@/util/index.js"
- import {
- IMG_URL
- } from '@/env'
- import {mapActions, mapState} from 'vuex'
- import tools from '@/common/tools.js'
- import api from '@/common/request/index'
- // 默认回调
- const callbackFun = () => {}
- // 自定义插件初始化
- const install = (Vue, vm) => {
- // 设置本地静态化
- Vue.prototype.$setStorage = setStorage
- // 获取本地静态化
- Vue.prototype.$getStorage = getStorage
- // 获取上一页
- Vue.prototype.$prePage = prePage
-
- // 全局绑定请求方法
- Vue.prototype.$api = api
-
- // 方法延迟保护函数
- Vue.prototype.$debounce = function debounce(fn, delay = 1000) {
-
- // 定时器,用来 setTimeout
- var timer
-
- // 返回一个函数,这个函数会在一个时间区间结束后的 delay 毫秒时执行 fn 函数
- return function() {
-
- // 保存函数调用时的上下文和参数,传递给 fn
- var context = this
- var args = arguments
-
- // 每次这个返回的函数被调用,就清除定时器,以保证不执行 fn
- clearTimeout(timer)
-
- // 当返回的函数被最后一次调用后(也就是用户停止了某个连续的操作),
- // 再过 delay 毫秒就执行 fn
- timer = setTimeout(function() {
- fn.apply(context, args)
- }, delay)
- }
- }
-
-
- // 全局混入方法
- Vue.mixin({
- data() {
-
- },
- computed:{
- ...mapState({
-
- }),
- $imgUrl(){
- return IMG_URL
- }
- },
- methods: {
- // 统计
- $st(callback = callbackFun, event = "0") {
- // 调用回调
- callback.call(this)
- }
- }
-
- })
-
- Vue.prototype.$tools = tools
- }
- export default {
- install
- }
|