Explorar o código

语音播放修复有时候没声音的bug1

zhangyujun %!s(int64=3) %!d(string=hai) anos
pai
achega
c4070311af
Modificáronse 17 ficheiros con 1198 adicións e 1165 borrados
  1. 0 3
      .browserslistrc
  2. 23 13
      .eslintrc.js
  3. 2 22
      .gitignore
  4. 232 11
      README.md
  5. 0 5
      babel.config.js
  6. 0 19
      jsconfig.json
  7. 911 877
      package-lock.json
  8. 30 23
      package.json
  9. 0 17
      public/index.html
  10. 0 32
      src/App.vue
  11. 0 60
      src/components/HelloWorld.vue
  12. 0 12
      src/main.js
  13. 0 27
      src/router/index.js
  14. 0 17
      src/store/index.js
  15. 0 5
      src/views/AboutView.vue
  16. 0 18
      src/views/HomeView.vue
  17. 0 4
      vue.config.js

+ 0 - 3
.browserslistrc

@@ -1,3 +0,0 @@
-> 1%
-last 2 versions
-not dead

+ 23 - 13
.eslintrc.js

@@ -1,17 +1,27 @@
 module.exports = {
-  root: true,
-  env: {
-    node: true
-  },
-  'extends': [
-    'plugin:vue/essential',
-    'eslint:recommended'
-  ],
+  parser: 'vue-eslint-parser',
   parserOptions: {
-    parser: '@babel/eslint-parser'
+    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 JSX
+      jsx: true,
+    },
   },
+  // settings: {
+  //   tsx: {
+  //     version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
+  //   }
+  // },
+  extends: [
+    'plugin:vue/vue3-recommended',
+    'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
+    '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: {
-    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
-    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
-  }
-}
+    // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
+    // e.g. "@typescript-eslint/explicit-function-return-type": "off",
+  },
+};

+ 2 - 22
.gitignore

@@ -1,23 +1,3 @@
-.DS_Store
 node_modules
-/dist
-
-
-# local env files
-.env.local
-.env.*.local
-
-# Log files
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-
-# Editor directories and files
-.idea
-.vscode
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
+dist
+package-lock

+ 232 - 11
README.md

@@ -1,24 +1,245 @@
-# vue2-mockexam
+# Vue3与TSX尝鲜版
+## 涉及到的主要依赖
+1. `vite@2.0.4`
+2. `vue@3.0.7`
+3. `vuex@4.0.0`
+4. `vue-router@4.0.4`
+5. `typescript@4.2.2`
 
-## Project setup
+## 准备工作
+1. 确保安装`yarn`
+```bash
+npm install yarn -g
 ```
-npm install
+2. 确保安装`vite`脚手架
+```bash
+npm install -g create-vite-app
+# or
+yarn add -g create-vite-app
 ```
 
-### Compiles and hot-reloads for development
+## 开始
+### 项目初始化
+```bash
+yarn create vite-app <project-name>
 ```
-npm run serve
+
+### 集成TS
+```bash
+yarn add --dev typescript
+```
+项目根目录创建配置文件:`tsconfig.json`:
+```js
+{
+  "include": ["./**/*.ts"],
+  "compilerOptions": {
+    "jsx": "react",
+    "target": "es2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
+    "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
+    // "lib": ["es2017.object"] /* Specify library files to be included in the compilation. */,
+    // "declaration": true /* Generates corresponding '.d.ts' file. */,
+    // "declarationMap": true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */
+    "sourceMap": true /* Generates corresponding '.map' file. */,
+    // "outFile": "./",                       /* Concatenate and emit output to single file. */
+    "outDir": "./dist" /* Redirect output structure to the directory. */,
+
+    "strict": true /* Enable all strict type-checking options. */,
+    "noUnusedLocals": true /* Report errors on unused locals. */,
+    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
+
+    "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
+    "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
+  }
+}
 ```
 
-### Compiles and minifies for production
+### 集成eslint
+```bash
+yarn add --dev eslint eslint-plugin-vue
 ```
-npm run build
+项目根目录创建配置文件`.eslintrc.js`:
+```js
+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 JSX
+      jsx: true,
+    },
+  },
+  // settings: {
+  //   tsx: {
+  //     version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
+  //   }
+  // },
+  extends: [
+    'plugin:vue/vue3-recommended',
+    'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
+    '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: {
+    // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
+    // e.g. "@typescript-eslint/explicit-function-return-type": "off",
+  },
+};
 ```
 
-### Lints and fixes files
+### 集成pritter
+```bash
+yarn add --dev prettier eslint-config-prettier eslint-plugin-prettier
 ```
-npm run lint
+项目根目录创建配置文件:`.prettierrc.js`:
+```js
+module.exports = {
+  semi: true,
+  trailingComma: "all",
+  singleQuote: true,
+  printWidth: 100,
+  tabWidth: 2,
+  endOfLine:"auto"
+};
+```
+
+到这一步,一个Vue3+TSX的项目就搭建起来了,以上配置文件的具体内容就不做解释了。
+
+### 修改入口文件
+因为默认项目模板是以`src/main.js`为入口的,我们需要把它修改为`src/main.ts`。  
+在`根目录的index.html`中修改入口文件的引用即可:
+```html
+... ...
+<body>
+  ... ...
+  <script type="module" src="/src/main.ts"></script>
+</body>
+</html>
+
 ```
 
-### Customize configuration
-See [Configuration Reference](https://cli.vuejs.org/config/).
+### 优化TS类型推断
+在src目录下,创建`shim.d.ts、source.d.ts`  
+
+`shim.d.ts`: (这个其实不太需要,因为项目中全是通过tsx开发的)
+```ts
+declare module '*.vue' {
+  import Vue from 'vue';
+  export default Vue;
+}
+```
+`source.d.ts`: (优化编译器提示,声明静态资源文件)
+```ts
+declare const React: string;
+declare module '*.json';
+declare module '*.png';
+declare module '*.jpg';
+```
+
+### 集成vue-router
+```bash
+yarn add --dev vue-router@4.0.4
+```
+这里可以去`npm官网`查找最新版本  
+在src目录下,`新建router文件夹`,并在文件夹内`创建index.ts`
+`index.ts`:
+```js
+import { RouteRecordRaw, createRouter, createWebHistory } from 'vue-router';
+
+const routes: RouteRecordRaw[] = [
+  {
+    path: '/',
+    name: 'Home',
+    component: () => import('../views/Home'),
+  },
+  {
+    path: '/about',
+    name: 'About',
+    component: () => import('../views/About'),
+  },
+];
+
+const router = createRouter({
+  history: createWebHistory(),
+  routes,
+});
+
+export default router;
+
+```  
+这里创建router的方式与之前不同,在vue3中,结合TS的类型推断,开发效率会高很多。  
+
+### 集成vuex
+
+```bash
+yarn add --dev vuex@4.0.0
+```
+在src目录下,新建store文件夹,并在文件夹内创建`index.ts`  
+
+`index.ts`:  
+```js
+import { state } from './state';
+import { createStore } from 'vuex';
+
+export default createStore({
+  state,
+  mutations: {},
+  actions: {},
+  modules: {},
+});
+```
+`state.js`:
+```js
+export interface State {
+  title: string;
+}
+
+export const state: State = {
+  title: 'Vue(v3) 与 tsx 的结合~',
+};
+```
+### main.ts
+最终main.ts中引入store、router:
+```js
+import { createApp } from 'vue';
+import App from './App';
+import router from './router';
+import store from './store';
+
+createApp(App).use(router).use(store).mount('#app');
+```  
+### TSX
+最终我们的组件代码,都会是这样的:`App.tsx`:  
+```js
+import { defineComponent } from 'vue';
+import {RouterLink, RouterView} from 'vue-router';
+import './style/main.scss'
+
+export default defineComponent({
+  name: 'App',
+  setup() {
+    return () => (
+      <>
+        <div id="nav">
+          <RouterLink to="/">Home</RouterLink> |
+          <RouterLink to="/about">About</RouterLink>
+        </div>
+        <RouterView/>
+      </>
+    );
+  }
+});
+```  
+自我感觉TSX比模板好多了,并且html、组件标签的属性都带有类型推断。
+
+## 结尾
+vue3正式版的发布,势必导致vue2的周边框架的集体更新,例如UI框架、基于Vue2的指令库等,作为这么久的白嫖党,也要为vue3社区的建设出一份力了。
+  
+   
+Vue3与TS的结合是大趋势,如果不适应TS,那还是建议使用Vue2吧。23333~
+  
+
+后续博主也将研究vite框架和vue3全家桶的新特性与API,争取输出有质量的文档。  
+***
+参考文章: [https://github.com/hyperMoss/vue-tsx](https://github.com/hyperMoss/vue-tsx)

+ 0 - 5
babel.config.js

@@ -1,5 +0,0 @@
-module.exports = {
-  presets: [
-    '@vue/cli-plugin-babel/preset'
-  ]
-}

+ 0 - 19
jsconfig.json

@@ -1,19 +0,0 @@
-{
-  "compilerOptions": {
-    "target": "es5",
-    "module": "esnext",
-    "baseUrl": "./",
-    "moduleResolution": "node",
-    "paths": {
-      "@/*": [
-        "src/*"
-      ]
-    },
-    "lib": [
-      "esnext",
-      "dom",
-      "dom.iterable",
-      "scripthost"
-    ]
-  }
-}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 911 - 877
package-lock.json


+ 30 - 23
package.json

@@ -1,31 +1,38 @@
 {
-  "name": "vue2-mockexam",
-  "version": "0.1.0",
-  "private": true,
+  "name": "vue_tsx",
+  "version": "0.0.0",
   "scripts": {
-    "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build",
-    "lint": "vue-cli-service lint",
-    "build:dev":"vue-cli-service build --mode test"
+    "dev": "vite --host",
+    "build:dev": "vite build --mode test",
+    "build": "vite build --mode production"
   },
   "dependencies": {
-    "core-js": "^3.8.3",
-    "vue": "^2.6.14",
-    "vue-router": "^3.5.1",
-    "vuex": "^3.6.2"
+    "axios": "^0.22.0",
+    "dayjs": "^1.10.8",
+    "vue": "3.0.11",
+    "vue-router": "^4.0.6",
+    "vuex": "4.0.0",
+    "vant": "^3.1.5"
   },
   "devDependencies": {
-    "@babel/core": "^7.12.16",
-    "@babel/eslint-parser": "^7.12.16",
-    "@vue/cli-plugin-babel": "~5.0.0",
-    "@vue/cli-plugin-eslint": "~5.0.0",
-    "@vue/cli-plugin-router": "~5.0.0",
-    "@vue/cli-plugin-vuex": "~5.0.0",
-    "@vue/cli-service": "~5.0.0",
-    "eslint": "^7.32.0",
-    "eslint-plugin-vue": "^8.0.3",
-    "sass": "^1.32.7",
-    "sass-loader": "^12.0.0",
-    "vue-template-compiler": "^2.6.14"
+    "@types/node": "^14.14.41",
+    "@typescript-eslint/eslint-plugin": "^4.22.0",
+    "@typescript-eslint/parser": "^4.22.0",
+    "@vitejs/plugin-vue": "^1.2.1",
+    "@vitejs/plugin-vue-jsx": "^1.1.3",
+    "@vue/compiler-sfc": "3.0.11",
+    "@vuedx/typecheck": "^0.6.3",
+    "@vuedx/typescript-plugin-vue": "^0.6.3",
+    "babel-polyfill": "^6.26.0",
+    "eslint": "^7.24.0",
+    "eslint-config-prettier": "^8.2.0",
+    "eslint-plugin-prettier": "^3.4.0",
+    "eslint-plugin-vue": "7.9.0",
+    "postcss-px-to-viewport": "^1.1.1",
+    "prettier": "^2.2.1",
+    "sass": "^1.32.11",
+    "typescript": "^4.2.4",
+    "vite": "2.6.13",
+    "vue-eslint-parser": "^7.6.0"
   }
 }

+ 0 - 17
public/index.html

@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width,initial-scale=1.0">
-    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
-    <title><%= htmlWebpackPlugin.options.title %></title>
-  </head>
-  <body>
-    <noscript>
-      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
-    </noscript>
-    <div id="app"></div>
-    <!-- built files will be auto injected -->
-  </body>
-</html>

+ 0 - 32
src/App.vue

@@ -1,32 +0,0 @@
-<template>
-  <div id="app">
-    <nav>
-      <router-link to="/">Home</router-link> |
-      <router-link to="/about">About</router-link>
-    </nav>
-    <router-view/>
-  </div>
-</template>
-
-<style lang="scss">
-#app {
-  font-family: Avenir, Helvetica, Arial, sans-serif;
-  -webkit-font-smoothing: antialiased;
-  -moz-osx-font-smoothing: grayscale;
-  text-align: center;
-  color: #2c3e50;
-}
-
-nav {
-  padding: 30px;
-
-  a {
-    font-weight: bold;
-    color: #2c3e50;
-
-    &.router-link-exact-active {
-      color: #42b983;
-    }
-  }
-}
-</style>

+ 0 - 60
src/components/HelloWorld.vue

@@ -1,60 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>{{ msg }}</h1>
-    <p>
-      For a guide and recipes on how to configure / customize this project,<br>
-      check out the
-      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
-    </p>
-    <h3>Installed CLI Plugins</h3>
-    <ul>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
-    </ul>
-    <h3>Essential Links</h3>
-    <ul>
-      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
-      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
-      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
-      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
-      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
-    </ul>
-    <h3>Ecosystem</h3>
-    <ul>
-      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
-      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
-      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
-      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
-      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
-    </ul>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped lang="scss">
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 0 - 12
src/main.js

@@ -1,12 +0,0 @@
-import Vue from 'vue'
-import App from './App.vue'
-import router from './router'
-import store from './store'
-
-Vue.config.productionTip = false
-
-new Vue({
-  router,
-  store,
-  render: h => h(App)
-}).$mount('#app')

+ 0 - 27
src/router/index.js

@@ -1,27 +0,0 @@
-import Vue from 'vue'
-import VueRouter from 'vue-router'
-import HomeView from '../views/HomeView.vue'
-
-Vue.use(VueRouter)
-
-const routes = [
-  {
-    path: '/',
-    name: 'home',
-    component: HomeView
-  },
-  {
-    path: '/about',
-    name: 'about',
-    // route level code-splitting
-    // this generates a separate chunk (about.[hash].js) for this route
-    // which is lazy-loaded when the route is visited.
-    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
-  }
-]
-
-const router = new VueRouter({
-  routes
-})
-
-export default router

+ 0 - 17
src/store/index.js

@@ -1,17 +0,0 @@
-import Vue from 'vue'
-import Vuex from 'vuex'
-
-Vue.use(Vuex)
-
-export default new Vuex.Store({
-  state: {
-  },
-  getters: {
-  },
-  mutations: {
-  },
-  actions: {
-  },
-  modules: {
-  }
-})

+ 0 - 5
src/views/AboutView.vue

@@ -1,5 +0,0 @@
-<template>
-  <div class="about">
-    <h1>This is an about page</h1>
-  </div>
-</template>

+ 0 - 18
src/views/HomeView.vue

@@ -1,18 +0,0 @@
-<template>
-  <div class="home">
-    <img alt="Vue logo" src="../assets/logo.png">
-    <HelloWorld msg="Welcome to Your Vue.js App"/>
-  </div>
-</template>
-
-<script>
-// @ is an alias to /src
-import HelloWorld from '@/components/HelloWorld.vue'
-
-export default {
-  name: 'HomeView',
-  components: {
-    HelloWorld
-  }
-}
-</script>

+ 0 - 4
vue.config.js

@@ -1,4 +0,0 @@
-const { defineConfig } = require('@vue/cli-service')
-module.exports = defineConfig({
-  transpileDependencies: true
-})

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio