婷婷久久综合九色综合,欧美成色婷婷在线观看视频,偷窥视频一区,欧美日本一道道一区二区

<tt id="bu9ss"></tt>
  • <span id="bu9ss"></span>
  • <pre id="bu9ss"><tt id="bu9ss"></tt></pre>
    <label id="bu9ss"></label>

    當(dāng)前位置:首頁 >  站長 >  編程技術(shù) >  正文

    typescript編寫微信小程序創(chuàng)建項目的方法

     2021-03-11 17:25  來源: 腳本之家   我來投稿 撤稿糾錯

      阿里云優(yōu)惠券 先領(lǐng)券再下單

    這篇文章主要介紹了typescript編寫微信小程序創(chuàng)建項目的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

    創(chuàng)建項目

    在微信開發(fā)者工具創(chuàng)建項目,在語言中選擇 TypeScript改造項目

    編輯 package.json 文件,修改 miniprogram-api-typings 和 typescript 版本

    {
    "name": "miniprogram-ts-quickstart",
    "version": "1.0.0",
    "description": "",
    "scripts": {
    "compile": "./node_modules/typescript/bin/tsc",
    "tsc": "node ./node_modules/typescript/lib/tsc.js"
    },
    "keywords": [],
    "author": "",
    "license": "",
    "dependencies": {
    },
    "devDependencies": {
    "typescript": "^4.1.3",
    "miniprogram-api-typings": "^2.12.1-beta.0"
    }
    }

    編輯 tsconfig.json 文件, 修改 lib 為 ["esnext"],支持最新語法, 刪除 typeRoots 配置項

    {
    "compilerOptions": {
    "strictNullChecks": true,
    "noImplicitAny": true,
    "module": "CommonJS",
    "target": "ES5",
    "allowJs": false,
    "experimentalDecorators": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strict": true,
    "removeComments": true,
    "pretty": true,
    "strictPropertyInitialization": true,
    "lib": ["esnext"]
    },
    "include": [
    "./**/*.ts"
    ],
    "exclude": [
    "node_modules"
    ]
    }

    執(zhí)行 npm install刪除項目下 typings 目錄, 的 復(fù)制 node_modules 下 miniprogram-api-typings 的 types 文件到項目根目錄

    在 miniprogram 下創(chuàng)建 interface 目錄并創(chuàng)建 IAppOption.ts 文件,最后編輯 app.ts 文件,

    // IAppOption.ts
    export default interface IAppOption {
    globalData: {
    text: string;
    }
    }
    // app.ts
    import IAppOption from "./interface/IAppOption";

    App<IAppOption>({
    globalData: {
    text: "Hello,Word!"
    },
    onLaunch() {
    }
    })

    在 詳細(xì) -> 本地設(shè)置 -> 調(diào)試基礎(chǔ)庫,直接選擇最新的

    使用 Promise 化的微信小程序api

    以前可以通過 miniprogram-api-promise 這個包來完成 api Promise 化,或者自己寫

    現(xiàn)在可以直接使用,比如 wx.getStorageInfo ,在 lib.wx.api.d.ts 中返回了 PromisifySuccessResultPromisifySuccessResult 返回了Promise

    getStorageInfo<TOption extends GetStorageInfoOption>(
    option?: TOption
    ): PromisifySuccessResult<TOption, GetStorageInfoOption>

    type PromisifySuccessResult<
    P,
    T extends AsyncMethodOptionLike
    > = P extends { success: any }
    ? void
    : P extends { fail: any }
    ? void
    : P extends { complete: any }
    ? void
    : Promise<Parameters<Exclude<T['success'], undefined>>[0]>

    兩種用法,大多數(shù)api都支持

    wx.getStorageInfo({
    success: () => {
    console.log('成功執(zhí)行')
    },
    fail: () => {
    console.log('失敗執(zhí)行')
    },
    complete: () => {
    console.log('接口調(diào)用結(jié)束')
    }
    })
    wx.getStorageInfo().then(() => {
    console.log('成功執(zhí)行')
    }).catch(() => {
    console.log('失敗執(zhí)行')
    }).finally(() => {
    console.log('接口調(diào)用結(jié)束')
    })

    源碼: https://github.com/NikolasSky/ts-miniprogram/tree/master/ts-miniprogram-base

    到此這篇關(guān)于typescript編寫微信小程序創(chuàng)建項目的方法的文章就介紹到這了,更多相關(guān)typescript開發(fā)微信小程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

    來源:腳本之家

    鏈接:https://www.jb51.net/article/205005.htm

    申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

    相關(guān)標(biāo)簽
    微信小程序

    相關(guān)文章

    熱門排行

    信息推薦