![](/img/trans.png)
[英]Laravel - [Vue warn]: Failed to mount component: template or render function not defined
[英][Vue warn]: Failed to mount component when using mixin with a parameter
从昨天开始,我一直在努力创建一个带有参数的 Vue mixin,我得到一个 [Vue warn]: Failed to mount component: template or render function not defined。 这是我的 JS 文件,包括 mixin:
export default (dataObject) => ({ data() { return { inputValue: '' } }, methods: { updateValue(newValue) { this.inputValue = newValue } }, mounted() { this.$bus.$on('value-changed', this.updateValue) }, beforeDestroy() { this.$bus.$off('value-changed'); }, computed: { filteredData() { if (this.inputValue.== '') { let newData = Object.keys(dataObject).filter(key => key.includes(this.inputValue)),reduce( (newData, current) => ((newData[current] = dataObject[current]), newData), {} ) return newData } else return dataObject } } })
这是我的 Vue 组件:
import searchLogic from '../logic/searchLogic.js' import { mapState } from 'vuex' export default { computed: {...mapState(['champions']), }, mixins: [searchLogic(this.champions)] }
导入此文件有效,因为当我尝试导入没有 arguments 的普通 mixin 时,它可以正常工作。 我也尝试过通过champions
和"champions"
而不是this.champions
但似乎没有一个工作。 mixin有问题吗? 我读到可以返回 function 返回 object 以在创建 mixins 时使用参数。
根据这篇文章,您应该能够静态传递参数,但不能动态传递。 https://forum.vuejs.org/t/pass-parameters-to-a-mixin-method/26401/3
但是,我从您收到的警告和您共享的代码中可以看出,您没有使用模板属性或 .vue 文件中的模板元素为组件定义任何模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.