如何使用 jsx/tsx 渲染修复错误未知的自定义 Vuetify 元素?
How to fix error unknown custom Vuetify element with jsx/tsx render?
我是 Vue 和 Vuetify 的新手。我正在使用 TSX——Typescript JSX——渲染创建简单的应用程序。浏览器中的应用程序 运行 在控制台中出现以下错误
[Vue warn]: Unknown custom element: <v-app> - did you register the
component correctly? For recursive components, make sure to provide
the "name" option.
found in
---> at src/App.vue
[Vue warn]: Unknown custom element: <v-content> - did you register the
component correctly? For recursive components, make sure to provide
the "name" option.
found in
---> at src/App.vue
...
这里是App.vue
<script lang="tsx">
import { Component, Vue } from "vue-property-decorator";
@Component
export default class App extends Vue {
render() {
return (
<div id="app">
<v-app>
<v-content>
<p>Hello World</p>
</v-content>
</v-app>
</div>
);
}
}
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
main.ts
import Vue from 'vue'
import './plugins/vuetify'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
plugins/vuetify.ts
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import 'vuetify/src/stylus/app.styl'
Vue.use(Vuetify, {
iconfont: 'md',
})
您可以在下面的 github link 中找到完整的项目文件
https://github.com/janucaria/vuetify-tsx-demo
在您的 App.vue 中,像这样导入所需的 Vuetify 组件:
<script lang="tsx">
import { Component, Vue } from "vue-property-decorator";
import { VApp, VContent } from 'vuetify/lib';
@Component({
components: {
'v-app': VApp,
'v-content': VContent
}
})
export default class App extends Vue {
render() {
return (
<div id="app">
<v-app>
<v-content>
<p>Hello World</p>
</v-content>
</v-app>
</div>
);
}
}
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
我是 Vue 和 Vuetify 的新手。我正在使用 TSX——Typescript JSX——渲染创建简单的应用程序。浏览器中的应用程序 运行 在控制台中出现以下错误
[Vue warn]: Unknown custom element: <v-app> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> at src/App.vue
[Vue warn]: Unknown custom element: <v-content> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> at src/App.vue
...
这里是App.vue
<script lang="tsx">
import { Component, Vue } from "vue-property-decorator";
@Component
export default class App extends Vue {
render() {
return (
<div id="app">
<v-app>
<v-content>
<p>Hello World</p>
</v-content>
</v-app>
</div>
);
}
}
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
main.ts
import Vue from 'vue'
import './plugins/vuetify'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
plugins/vuetify.ts
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import 'vuetify/src/stylus/app.styl'
Vue.use(Vuetify, {
iconfont: 'md',
})
您可以在下面的 github link 中找到完整的项目文件 https://github.com/janucaria/vuetify-tsx-demo
在您的 App.vue 中,像这样导入所需的 Vuetify 组件:
<script lang="tsx">
import { Component, Vue } from "vue-property-decorator";
import { VApp, VContent } from 'vuetify/lib';
@Component({
components: {
'v-app': VApp,
'v-content': VContent
}
})
export default class App extends Vue {
render() {
return (
<div id="app">
<v-app>
<v-content>
<p>Hello World</p>
</v-content>
</v-app>
</div>
);
}
}
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>