vue 解决循环引用组件报错

做项目时遇到使用循环组件,因为模式一样,只有数据不一样。但是按照普通的组件调用格式来做时报错,错误信息为Unknown custom element: <pop> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

查询了官方文档,还有其他的资料,发现是循环调用组件时,组件比vue实例后创建,官方文档里写组件必须先于实例化引入,所以说组件没有正确的引入。

解决的方式是全局引入组件,并且在vue实例化前。

具体代码如下:若在项目中,一般是在main.js里引入

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
// import iView from 'iView';
import { Poptip, Input, Spin, Icon } from 'iView';
import 'iview/dist/styles/iview.css';
import './components/css/main.css';
import './components/css/main.min.css';
import '../my-theme/index.less';
import 'video.js/dist/video-js.css';
import 'vue-video-player/src/custom-theme.css';

// require('videojs-contrib-hls/dist/videojs-contrib-hls');

Vue.component('Poptip', Poptip);
Vue.component('Input', Input);
Vue.component('Spin', Spin);
Vue.component('Icon', Icon);
Vue.config.productionTip = false
/* 全局引入方式 */
// Vue.use(iView);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

猜你喜欢

转载自blog.csdn.net/corey_mengxiaodong/article/details/81074957
今日推荐