1、新建全局组件components/Item.vue

1-1、新建全局组件

  1. //src/utils/config.js
  2. import Item from '@/components/Item.vue
  3. Vue.components('Item',Item)

1-2、Loading组件

  1. <template>
  2. <div>加载中...</div>
  3. </template>
  4. <script>
  5. export default {
  6. name:"Loading"
  7. }
  1. //在uitls/config.js中配置
  2. import Vue from 'vue';
  3. import Loading from '@/components/Loading'
  4. Vue.component("Loading",Loading)
  5. export default Vue;

2、新建全局过滤器

  1. //src/utils/config.js
  2. Vue.filter("format", function (val) {
  3. if (val.length > 5) {
  4. val = val.slice(0, 5) + "..."
  5. }
  6. return val
  7. })