延續前面的兩篇文章: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地址