国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序uniapp+vue3+ts+pinia的環(huán)境搭建

這篇具有很好參考價值的文章主要介紹了微信小程序uniapp+vue3+ts+pinia的環(huán)境搭建。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一.創(chuàng)建uniapp項(xiàng)目

通過vue-cli創(chuàng)建

npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project

二.安裝依賴:

1.pnpm i

2.運(yùn)行項(xiàng)目:

將package.json的

 "dev:mp-weixin": "uni -p mp-weixin",
 改為 "serve": "uni -p mp-weixin",
 后續(xù)可以用pnpm run serve啟動微信小程序開發(fā)工具

3.導(dǎo)入微信小程序開發(fā)工具

打開微信開發(fā)者工具, 導(dǎo)入 dist\dev\mp-weixin 運(yùn)行

三. TS 類型校驗(yàn)

在tsconfig.json文件中"compilerOptions"配置項(xiàng)內(nèi)添加"ignoreDeprecations": “5.0”

"compilerOptions": {
    "ignoreDeprecations": "5.0"
  },

額外配置Ts類型校驗(yàn):

  1. 安裝類型聲明文件:
pnpm i -D @types/wechat-miniprogram @uni-helper/uni-app-types
2. 配置tsconfig.json:
// tsconfig.json
{
  "extends": "@vue/tsconfig/tsconfig.json",
  "compilerOptions": {
    "ignoreDeprecations": "5.0",
    "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "lib": ["esnext", "dom"],
    "types": [
      "@dcloudio/types",
      "@types/wechat-miniprogram",
      "@uni-helper/uni-app-types"
    ]
  },
   // vue 編譯器類型,校驗(yàn)標(biāo)簽類型
   "vueCompilerOptions": {
    "nativeTags": ["block","component","template","slot"],
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}

在配置完成后,vue組件就會提示報(bào)錯信息

四. JSON 注釋問題

在vscode面板中,點(diǎn)擊右小角設(shè)置按鈕→點(diǎn)擊設(shè)置→在搜索設(shè)置中搜索“文件關(guān)聯(lián)”→找到Files: Associations的配置項(xiàng)→點(diǎn)擊添加項(xiàng)→把 manifest.jsonpages.json 設(shè)置為 jsonc即可;

五. 安裝uview-plus

  1. 安裝
pnpm add uview-plus
pnpm add dayjs
pnpm add clipboard

注意: 此安裝方式必須要按照npm方式安裝的配置中的說明配置了才可用,且項(xiàng)目名稱不能有中文字符。

因?yàn)閡view-plus依賴SCSS,所以必須要安裝此插件,否則無法正常運(yùn)行。

// 安裝sass
pnpm add sass -D

// 安裝sass-loader,注意需要版本10,否則可能會導(dǎo)致vue與sass的兼容問題而報(bào)錯
pnpm add sass-loader@10 -D
  1. 配置步驟

引入uview-plus主JS庫:在項(xiàng)目src目錄中的main.js中,引入并使用uview-plus的JS庫,注意這兩行要放在const app = createSSRApp(App)之后。

// main.js
import uviewPlus from 'uview-plus'

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  app.use(uviewPlus)
  return {
    app
  }
}
// #endif

定義uview-plus

//src/types/uview.d.ts
declare module "uview-plus"

引入uview-plus的全局CSS主題文件: 在項(xiàng)目根目錄的uni.scss中引入此文件。

/* uni.scss */
@import 'uview-plus/theme.scss';

//App.vue

<style lang="scss">
/* 注意要寫在第一行,同時給style標(biāo)簽加入lang="scss"屬性 */
@import "uview-plus/index.scss";
</style>
...

配置easycom組件模式:需要在項(xiàng)目src目錄的pages.json中進(jìn)行

// pages.json
{
	"easycom": {
		// 注意一定要放在custom里,否則無效,https://ask.dcloud.net.cn/question/131175
		"custom": {
			"^u--(.*)": "uview-plus/components/u-$1/u-$1.vue",
			"^up-(.*)": "uview-plus/components/u-$1/u-$1.vue",
	        "^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue"
		}
	},
	
	// 此為本身已有的內(nèi)容
	"pages": [
		// ......
	]
}

六. 配置pinia持久化

安裝

pnpm add pinia@2.0.33

在main.ts頁面

import { createSSRApp } from "vue"
import App from "./App.vue"
import uviewPlus from 'uview-plus'
// 導(dǎo)入 pinia 實(shí)例
import pinia from './stores'

export function createApp() {
  const app = createSSRApp(App);
  app.use(uviewPlus)
  app.use(pinia)
  return {
    app,
  };
}
//stores/index
import { createPinia } from 'pinia'
import persist from 'pinia-plugin-persistedstate'

// 創(chuàng)建 pinia 實(shí)例
const pinia = createPinia()
// 使用持久化存儲插件
pinia.use(persist)

// 默認(rèn)導(dǎo)出,給 main.ts 使用
export default pinia
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserInfoStore = defineStore(
  'userInfo', 
  () => {
    const userInfo = ref()
    const setUserInfo = (val) => {
      userInfo.value = val
    }
    // 清理用戶信息,退出時使用
    const clearUserInfo = () => {
      userInfo.value = undefined
    }
    return {
      userInfo,
      setUserInfo,
      clearUserInfo,
    }
  },
  // 默認(rèn)持續(xù)化保存
  {
    persist:{
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key,value)
        },
      }
    }
  }
)

七. 封裝http請求

// src/utils/http.ts
 
// 請求基地址
const baseURL = 'xxxx'
 
// 攔截器配置
const httpInterceptor = {
  // 攔截前觸發(fā)
  invoke(options: UniApp.RequestOptions) {
    // 1. 非 http 開頭需拼接地址
    if (!options.url.startsWith('http')) {
      options.url = baseURL + options.url
    }
    // 2. 請求超時
    options.timeout = 10000
    // 3. 添加小程序端請求頭標(biāo)識
    options.header = {
      'source-client': 'miniapp',
      ...options.header,
    }
    // 4. 添加 token 請求頭標(biāo)識
    const memberStore = useMemberStore()
    const token = memberStore.profile?.token
    if (token) {
      options.header.Authorization = token
    }
  },
}
 
// 攔截 request 請求
uni.addInterceptor('request', httpInterceptor)
// 攔截 uploadFile 文件上傳
uni.addInterceptor('uploadFile', httpInterceptor)
/**
 * 請求函數(shù)
 * @param  UniApp.RequestOptions
 * @returns Promise
 *  1. 返回 Promise 對象,用于處理返回值類型
 *  2. 獲取數(shù)據(jù)成功
 *    2.1 提取核心數(shù)據(jù) res.data
 *    2.2 添加類型,支持泛型
 *  3. 獲取數(shù)據(jù)失敗
 *    3.1 401錯誤  -> 清理用戶信息,跳轉(zhuǎn)到登錄頁
 *    3.2 其他錯誤 -> 根據(jù)后端錯誤信息輕提示
 *    3.3 網(wǎng)絡(luò)錯誤 -> 提示用戶換網(wǎng)絡(luò)
 */
type Data<T> = {
  code: string
  msg: string
  result: T
}
// 2.2 添加類型,支持泛型
export const http = <T>(options: UniApp.RequestOptions) => {
  // 1. 返回 Promise 對象
  return new Promise<Data<T>>((resolve, reject) => {
    uni.request({
      ...options,
      // 響應(yīng)成功
      success(res) {
        // 狀態(tài)碼 2xx,參考 axios 的設(shè)計(jì)
        if (res.statusCode >= 200 && res.statusCode < 300) {
          // 2.1 提取核心數(shù)據(jù) res.data
          resolve(res.data as Data<T>)
        } else if (res.statusCode === 401) {
          // 401錯誤  -> 清理用戶信息,跳轉(zhuǎn)到登錄頁
          const memberStore = useMemberStore()
          memberStore.clearProfile()
          uni.navigateTo({ url: '/pages/login/login' })
          reject(res)
        } else {
          // 其他錯誤 -> 根據(jù)后端錯誤信息輕提示
          uni.showToast({
            icon: 'none',
            title: (res.data as Data<T>).msg || '請求錯誤',
          })
          reject(res)
        }
      },
      // 響應(yīng)失敗
      fail(err) {
        uni.showToast({
          icon: 'none',
          title: '網(wǎng)絡(luò)錯誤,換個網(wǎng)絡(luò)試試',
        })
        reject(err)
      },
    })
  })
}
八 . 其他配置
  1. vue3自動按需導(dǎo)入:

  2. //vite.config.ts
     
    import { defineConfig } from 'vite'
    import uni from '@dcloudio/vite-plugin-uni'
    import AutoImport from 'unplugin-auto-import/vite'
     
    // https://vitejs.dev/config/
    export default defineConfig({
      build: {
        sourcemap: process.env.NODE_ENV === 'development',
      },
      plugins: [
        uni(),
        AutoImport({ // 使用
          imports: ['vue'],
          dts: 'src/auto-import.d.ts',
          // 如有用到eslint記得加上寫段,沒有用到可以忽略
          eslintrc: {
            enabled: true,
          },
        })
      ],
    })
    

寫在最后:這一篇是在網(wǎng)上借鑒的微信小程序的環(huán)境搭建文章,跟著一步一步搭建下來并且做一些筆記,跟著這篇文章的步驟一步一步來,搭建出來是沒問題的。文章來源地址http://www.zghlxwxcb.cn/news/detail-846527.html

到了這里,關(guān)于微信小程序uniapp+vue3+ts+pinia的環(huán)境搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • uniapp--- 微信小程序 用戶隱私新規(guī)相關(guān)代碼調(diào)整【vue3+ts+uView框架】

    uniapp--- 微信小程序 用戶隱私新規(guī)相關(guān)代碼調(diào)整【vue3+ts+uView框架】

    官方公告地址:https://developers.weixin.qq.com/community/develop/doc/00042e3ef54940ce8520e38db61801 用戶隱私保護(hù)指引填寫說明地址:https://developers.weixin.qq.com/miniprogram/dev/framework/user-privacy/ 1) 需要在9月15前更新完畢,否則會無法使用獲取手機(jī)號 手機(jī)相冊等相關(guān)信息。 2) 微信小程序開發(fā)工具

    2024年02月09日
    瀏覽(30)
  • uniapp+vue3+ts--編寫微信小程序?qū)觘簽寶簽署時跳轉(zhuǎn)刷臉效果(人臉識別)中間頁代碼

    uniapp+vue3+ts--編寫微信小程序?qū)觘簽寶簽署時跳轉(zhuǎn)刷臉效果(人臉識別)中間頁代碼

    e簽寶內(nèi)嵌H5方式集成簽署頁的文檔說明:https://open.esign.cn/doc/opendoc/case3/ahb0sg 簽署時跳轉(zhuǎn)刷臉效果示意圖: 1. 在文件夾新建一個文件,路徑為pages/middle/index,并在pages.json中注冊。【ps這個路徑要跟e簽寶后臺定義的中間頁路徑一致】 2.通過上面文檔步驟進(jìn)行相關(guān)代碼編寫,下面

    2024年01月25日
    瀏覽(110)
  • 使用 Vite + Vue3 + Element-Plus + Pinia + Ts 搭建 Vue3 項(xiàng)目

    使用 Vite + Vue3 + Element-Plus + Pinia + Ts 搭建 Vue3 項(xiàng)目

    Vite 需要 Node.js 版本 14.18+,16+。然而,有些模板需要依賴更高的 Node 版本才能正常運(yùn)行,當(dāng)你的包管理器發(fā)出警告時,請注意升級你的 Node 版本。 首先 npm 輸入: Project name :項(xiàng)目名稱 Select a framework :選擇一個框架 Select a variant :選擇 ts 或者 js 輸入項(xiàng)目名稱后選擇 vue 選擇

    2024年02月09日
    瀏覽(27)
  • Vite4+Typescript+Vue3+Pinia 從零搭建(2) - ts配置

    項(xiàng)目代碼同步至碼云 weiz-vue3-template 關(guān)于tsconfig的配置字段可查看其他文檔,如 typeScript tsconfig配置詳解 文件修改如下: 修改文件如下: 新建文件夾 types ,用來存放類型定義。比如新建 index.d.ts : 后續(xù)也可以新增其他文件,比如 global.d.ts 存放全局定義, router.d.ts 存放路由定

    2024年02月05日
    瀏覽(102)
  • 使用vue3 + TS + Pinia + Vant4 + vite搭建商城H5項(xiàng)目框架

    使用vue3 + TS + Pinia + Vant4 + vite搭建商城H5項(xiàng)目框架

    本文主要將如何利用搭建一個初始化的商城H5項(xiàng)目框架。初始化階段使用的技術(shù)棧有:vue3.2、vue-router、?TS 、 Pinia 、 Vant4、Less、vite ????????????????????????node -v 檢測是否有安裝node.js,未安裝請先去官網(wǎng)安裝node.js ? ? ? ? 終端輸入:?npm?init vite ????????自定

    2024年02月12日
    瀏覽(96)
  • 從0開始搭建一個vue3+vite+ts+pinia+element-plus的項(xiàng)目

    從0開始搭建一個vue3+vite+ts+pinia+element-plus的項(xiàng)目

    前言:vue3+ts+vite大家已經(jīng)都開始用了,最近也在學(xué)習(xí),基本上是零基礎(chǔ)開始ts的學(xué)習(xí),很多語法知識是邊寫邊查,沒有系統(tǒng)的學(xué)習(xí)ts。此處展示從零開始,搭建的一個框架,方便拿來即用! 其中框架選擇vue,語言選擇typeScript 項(xiàng)目啟動成功以后如下所示: 為了方便日常工作中

    2024年02月06日
    瀏覽(28)
  • 【vue3】uniapp 微信小程序 打包優(yōu)化【超詳細(xì)】

    【vue3】uniapp 微信小程序 打包優(yōu)化【超詳細(xì)】

    使用HBuilder編輯器編譯uniapp的項(xiàng)目轉(zhuǎn)為微信小程序,并上傳發(fā)布項(xiàng)目 微信小程序官網(wǎng)限制發(fā)布的主包大小不能超過2mb,我的項(xiàng)目編譯后大小為3mb 1.vendor.js文件過大,打包的時候并沒有設(shè)置為mini版 2.項(xiàng)目的主包太大,并沒有分包出去(后面會詳細(xì)說明如何分包) 1.把微信小程序右

    2024年02月09日
    瀏覽(178)
  • 【vue】uniapp vue3 vite代理設(shè)置問題【H5 微信小程序】

    基于vue3版本的uniapp運(yùn)行h5和微信小程序 uniapp運(yùn)行h5請求接口成功,運(yùn)行微信小程序請求接口不成功 vite.config.ts配置proxy .env配置請求接口域名 request.ts 請求接口文件 微信小程序識別不了代理的配置 需要判斷當(dāng)前是h5還是微信小程序端,對請求接口文件進(jìn)行修改,其他文件不修

    2024年02月09日
    瀏覽(26)
  • vue3+uniapp在微信小程序?qū)崿F(xiàn)一個2048小游戲

    vue3+uniapp在微信小程序?qū)崿F(xiàn)一個2048小游戲

    微信小程序搜索《靜遠(yuǎn)的工具箱》:偶數(shù)求和那個功能

    2024年04月12日
    瀏覽(28)
  • 【Vue H5項(xiàng)目實(shí)戰(zhàn)】從0到1的自助點(diǎn)餐系統(tǒng)—— 搭建腳手架(Vue3.2 + Vite + TS + Vant + Pinia + Node.js)

    【Vue H5項(xiàng)目實(shí)戰(zhàn)】從0到1的自助點(diǎn)餐系統(tǒng)—— 搭建腳手架(Vue3.2 + Vite + TS + Vant + Pinia + Node.js)

    H5 項(xiàng)目基于 Web 技術(shù),可以在智能手機(jī)、平板電腦等移動設(shè)備上的瀏覽器中運(yùn)行,無需下載和安裝任何應(yīng)用程序,且H5 項(xiàng)目的代碼和資源可以集中在服務(wù)器端進(jìn)行管理,只需更新服務(wù)器上的代碼,即可讓所有顧客訪問到最新的系統(tǒng)版本。 本系列將以肯德基自助點(diǎn)餐頁面為模板

    2024年02月13日
    瀏覽(133)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包