官方文档
1 | // Vue.js 的插件应该有一个公开方法 install。这个方法的第一个参数是 Vue 构造器,第二个参数是一个可选的选项对象: |
alert插件开发
先写个alert组件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36<template>
<div class="ComAlert">
<div class="content" v-for="(item, index) in content" :key="index">{{item}}</div>
</div>
</template>
<script>
export default {
name: 'ComAlert',
data () {
return {
content: [],
timer: []
}
},
created () {
},
methods: {
push (text) {
const s = 2000
this.content.unshift(text)
const timer = setTimeout(() => {
this.content.pop()
}, s)
this.timer.push(timer)
}
}
}
</script>
<style scoped lang="less" rel="stylesheet/less">
@import "./Alert.less";
</style>再写个 alert.js
1 | import ComAlert from './Alert.vue' |
mian.js
1
2
3import Alert from './components/Alert/Alert'
Vue.use(Alert)调用
1.8 1
this.$_alert('提示内容')