我最近切换到使用打字稿的类组件,并在我的网站上出现此错误。这个错误在 Firefox 上,但在 chrome 上我得到
"TypeError: Cannot read property '$createElement' of undefined"
(found in <Root>)
查找我能找到的最接近的答案是将组件切换到路由器文件中的组件。但我检查过,我的一切似乎都很好。
这是我文件中的一些尝试
导航
<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { mapGetters } from 'vuex';
import Db from './Db.vue';
@Component({
components: { Db }
})
export default class Nav extends Vue {
get user() { return this.$store.state.user };
get token() { return this.$store.state.token };
logout() {
this.$store.dispatch('setState', {
token: '',
user: '',
db: '',
databases: []
});
this.$router.push('/');
};
};
<script lang="ts">
import Vue from 'vue';
import axios from 'axios';
import { Component } from 'vue-property-decorator';
@Component({
})
export default class Login extends Vue {
//state
username = '';
password = '';
usernameError =false;
passwordError = false;
error: string|number = '';
//methods
async login(): Promise<void> {
...
};
...
//lifecycle
mounted() {
console.log("HELLO WORLD I AM")
if (this.$store.state.token)
this.$router.push('/discover');
}
}
</script>
这是完整的谷歌错误
TypeError: Cannot read property '$createElement' of undefined
at render (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"713dcdf0-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vuetify-loader/lib/loader.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/App.vue?vue&type=template&id=7ba5bd90& (app.js:1461), <anonymous>:6:16)
at options.render (index.js?6435:83)
at createFunctionalComponent (vue.runtime.esm.js?2b0e:3058)
at createComponent (vue.runtime.esm.js?2b0e:3231)
at _createElement (vue.runtime.esm.js?2b0e:3428)
at createElement (vue.runtime.esm.js?2b0e:3353)
at vm.$createElement (vue.runtime.esm.js?2b0e:3488)
at Proxy.render (main.ts?bc82:19)
at Vue._render (vue.runtime.esm.js?2b0e:3542)
at Vue.updateComponent (vue.runtime.esm.js?2b0e:4060)
logError @ vue.runtime.esm.js?2b0e:1888
globalHandleError @ vue.runtime.esm.js?2b0e:1879
handleError @ vue.runtime.esm.js?2b0e:1839
Vue._render @ vue.runtime.esm.js?2b0e:3544
updateComponent @ vue.runtime.esm.js?2b0e:4060
get @ vue.runtime.esm.js?2b0e:4473
Watcher @ vue.runtime.esm.js?2b0e:4462
mountComponent @ vue.runtime.esm.js?2b0e:4067
Vue.$mount @ vue.runtime.esm.js?2b0e:8409
eval @ main.ts?bc82:15
./src/main.ts @ app.js:17260
__webpack_require__ @ app.js:727
fn @ app.js:101
1 @ app.js:17658
__webpack_require__ @ app.js:727
(anonymous) @ app.js:794
(anonymous) @ app.js:797
火狐
TypeError: "_vm is undefined"
render App.vue:3
render index.js:83
VueJS 5
render main.ts:19
VueJS 6
<anonymous> main.ts:15
ts app.js:17260
__webpack_require__ app.js:727
fn app.js:101
1 app.js:17658
__webpack_require__ app.js:727
<anonymous> app.js:794
<anonymous> app.js:797