回到顶部 js文件
export default {install (Vue) {Vue.directive('back-top', {inserted (el, binding) {let e = binding.arg || 'click'el.addEventListener(e, () => {var top = document.body.scrollTopvar timer = setInterval(() => {top -= 50if (top <= 0) {top = 0clearInterval(timer)}document.documentElement.scrollTop = document.body.scrollTop = top}, 20)})}})}}
在mainjs引入 Vue.use('name')