当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue如何解决循环引用组件报错的问题

vue如何解决循环引用组件报错的问题

2018年10月07日  | 移动技术网IT编程  | 我要评论

叛儿嬉春,非主流dj慢摇,儿歌免费下载

问题由来

最近在做项目的时候遇到使用循环组件,因为模式一样,只有数据不一样。按照普通组件调用格式来做的时候总是报错,错误信息为[vue warn]: unknown custom element: <selfile> - did you register the component correctly? for recursive components, make sure to provide the "name" option.

解决方案

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

解决方式

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

具体到我们项目中,就是在main.js里引入。

具体代码如下main.js:

import vue from 'vue'
import app from './app'
import router from './router'
import store from './store';
import iview from 'iview';
import './styles/index.less'
import {vtable,vpagination} from 'vue-easytable'
import 'vue-easytable/libs/themes-base/index.css'
import axios from './utils/axiosplugin'
import './styles/button.css'
import './styles/common.css'
// require('./mock/mock')
import selfile from './views/file/selfile.vue'

vue.use(iview);
vue.use(axios);

vue.component(vtable.name, vtable)
vue.component(vpagination.name, vpagination)
vue.component("selfile",selfile)

vue.config.productiontip = false

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

用上面的方法全局引入组件就可以解决循环引用组件报错的问题。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网