后臺用 kkFileView 做預覽文檔的功能, 前端增加預覽按鈕, 按鈕封裝成了一個組件, 具有預覽功能的頁面引入組件, 添加到指定位置即可
問題: 每個頁面到增加引入預覽組件太麻煩, 做成全局的(很多業務都有預覽功能)
寫好的預覽組件是 DocumentPreview .vue
把預覽組件放到 DocumentPreview 文件夾下并新建 index.js文件
```
import preview from './DocumentPreview.vue'
const DocumentPreview = {
// install 為Vue實例上的一個方法
install: function(Vue) {
// 注冊全局組件
Vue.component('DocumentPreview', preview)
}
}
// 導出組件
export default DocumentPreview
```
main.js 文件
```
import DocumentPreview from '@/components/DocumentPreview'
// 把文檔預覽組件添加到全局
Vue.use(DocumentPreview)
```