我想知道为什么这个简单的代码会出现警告和错误。我正在使用 vue 模板。这是我的第一个 Vue 应用程序,因此请提供更多详细信息,以便我可以跟进。
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'props' of undefined"
found in
---> <App> at src/App.vue
<Root>
vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read property 'props' of undefined
at normalizeProps (vue.runtime.esm.js?2b0e:1419)
at mergeOptions (vue.runtime.esm.js?2b0e:1521)
at mergeOptions (vue.runtime.esm.js?2b0e:1535)
at Function.Vue.extend (vue.runtime.esm.js?2b0e:5153)
at createComponent (vue.runtime.esm.js?2b0e:3184)
at _createElement (vue.runtime.esm.js?2b0e:3416)
at createElement (vue.runtime.esm.js?2b0e:3353)
at vm._c (vue.runtime.esm.js?2b0e:3485)
at Proxy.render (eval at ./node_modules...
这是子 vue
Animakit.vue
<template>
<div id="Animakit">
In Animakit
</div>
</template>
<script>
import firstOne from '../animakit.js'
export default {
name: 'Animakit',
mixins: [firstOne],
mounted: function () { this.firstOne() }
}
</script>
这是主要的App vue
App.vue
<template>
<div id="app">
<Animakit></Animakit>
<div>hello in App.vue </div>
</div>
</template>
<script>
import Animakit from './components/Animakit.vue'
export default {
components: {
'Animakit': Animakit
}
}
</script>
App vue就是这样使用的。
main.js
import Vue from 'vue';
import BootstrapVue from 'bootstrap-vue';
import axios from 'axios';
import App from './App.vue';
const http = axios.create({
baseURL: process.env.BACKEND_URL ? process.env.BACKEND_URL : 'http://localhost/todos',
});
Vue.prototype.$http = http;
Vue.use(BootstrapVue);
Vue.config.productionTip = false;
new Vue({
render: (h) => h(App),
}).$mount('#app');
JavaScript 文件的内容 animakit.js
function firstOne() {
}
export default firstOne;
最佳答案
Mixin 配置与组件配置非常相似。要创建一个名为 firstOne
的方法,您需要执行如下操作:
export default {
methods: {
firstOne () {
}
}
};
Vue 会自动将 mixin 配置合并到组件的配置中。官方文档中有更多相关内容,https://v2.vuejs.org/v2/guide/mixins.html#Option-Merging .
关于javascript - Vuejs渲染错误: "TypeError: Cannot read property ' props' of undefined"Vuejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58567463/