簡體   English   中英

[Vue 警告]:使用帶有參數的 mixin 時無法掛載組件

[英][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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM