简体   繁体   中英

How to fix error unknown custom Vuetify element with jsx/tsx render?

I am new to Vue and Vuetify. I am create simple app using TSX --the Typescript JSX-- rendering. The app running in the browser with the following error in the console

[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

...

here the 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',
})

you can find the complete project files in github link below https://github.com/janucaria/vuetify-tsx-demo

In your App.vue, import the required Vuetify components like so:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM