延续前面的两篇文章:css
第三篇新鲜出炉,主要是说一下,官网推荐vite与以前上的用法区别,以及使用typescript实战一个类element-ui的Dialog组件,使用较高级的Vue3.0的API~_~html
实际上就是先启动服务(koa),若是你须要某一个文件,再进行编译。这就形成Vite启动服务的速度比Webpack快了不少,即“按需编译”。vue
须要咱们注意的是:git
使用vite初始化项目github
npm init vite-app <project-name> cd <project-name> npm install npm run dev
//.eslintrc.jsweb
module.exports = { parser: 'vue-eslint-parser', parserOptions: { parser: '@typescript-eslint/parser', // Specifies the ESLint parser ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features sourceType: 'module', // Allows for the use of imports ecmaFeatures: { tsx: true, // Allows for the parsing of tsx // jsx: true,// Allows for the parsing of JSX }, }, plugins: ['@typescript-eslint'], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:vue/vue3-recommended', 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ], rules: { // js/ts 'eol-last': 'error', 'no-trailing-spaces': 'error', 'comma-style': ['error', 'last'], 'comma-dangle': ['error', 'always-multiline'], quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }], camelcase: ['error', { properties: 'never' }], semi: ['error', 'never'], indent: ['error', 2, { SwitchCase: 1 }], 'object-curly-spacing': ['error', 'always'], 'arrow-parens': ['error', 'as-needed'], '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/member-delimiter-style': [ 'error', { multiline: { delimiter: 'none', requireLast: false, }, singleline: { delimiter: 'semi', requireLast: true, }, }, ], // vue 'vue/no-v-html': 'off', 'vue/singleline-html-element-content-newline': 'off', 'vue/html-self-closing': [ 'error', { html: { void: 'never', normal: 'never', component: 'always', }, }, ], 'vue/max-attributes-per-line': [ 'error', { singleline: 3, multiline: 1, }, ], 'vue/require-default-prop': 'off', 'vue/html-closing-bracket-spacing': 'error', }, };
//vue-shim.d.ts declare module '*.vue' { import { Component, ComponentPublicInstance } from 'vue' const _default: Component & { new(): ComponentPublicInstance<any> } export default _default } //source.d.ts import Vue from 'vue' declare module '*.vue' { export default Vue } declare module '*.json' declare module '*.png' declare module '*.jpg'
//dialog.tstypescript
//dialog抽离的逻辑npm
// 全局引用element-ui
import Dialog from './components/dialog/index' const app = createApp(App) app.component(Dialog.name, Dialog)
// mask蒙层组件json
//使用方式 v-model.modelValue(原:visible.sync="dialogVisible"上一篇有介绍)
<elDialog v-model.modelValue="dialogVisible" title="提示" width="30vw" @close="handleClose"> <p>这是一段信息~~~</p> <div slot="footer" class="dialog-footer"> <button @click="handleClose" class="el-button el-button--default">取 消</button> <button type="primary" class="el-button el-button--primary" @click="dialogVisible = false">确 定</button> </div> </elDialog>
至此,使用vue3.0+typescript开发dialog组件后,对vue3.0的开发有了进一步的了解。这个过程当中,须要注意安装插件的版本。若是报错了,估计就是版本安装不对。下一篇就开始介绍router了~但愿你们喜欢~
代码github地址