如何在 tsx 文件上使用 Vue

index.tsx

import Vue from 'vue'
new Vue({
    render() {
        return <div id="app">hello world</div>
    }
}).$mount('#app')

webpack.js

const path = require('path');
module.exports = {
    resolve: {
        extensions: ['.tsx', '.ts', '.js', '.vue', '.json'],
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        }
    }
};

网络上大部分的教程都是在 .vue 文件中使用 script 标签添加 tsx lang 实现,如何直接在 tsx 中编写 Vue?

阅读 5.5k
1 个回答
import { Vue, Component } from 'vue-property-decorator';

@Component
export default class CommonView extends Vue {
  public render() {
    return <div />;
  }
}

命名为tsx后缀就好了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题