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

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

這篇具有很好參考價(jià)值的文章主要介紹了Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1、安裝 Taro 腳手架工具

npm install -g @tarojs/cli
yarn global add @tarojs/cli

2、taro 初始化項(xiàng)目

taro init taro-app

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

安裝 taro-ui

  • cd taro-app
  • yarn add taro-ui

全局引入taro-ui樣式

import 'taro-ui/dist/style/index.scss'
3、項(xiàng)目路由路徑
  • page 對(duì)應(yīng)項(xiàng)目路徑
  • lazyCodeLoading 組件按需注入
  • Taro.navigateTo({url: xxx}) 小程序內(nèi)部跳轉(zhuǎn)
export default {
    "lazyCodeLoading": "requiredComponents",
    pages: [
        'pages/index/index',
        'pages/statistics/index',
        'pages/my/index',
        'pages/about/index',
        'pages/contact/index',
        'pages/webview/index'
    ],
    // ...
}
4、全局添加分享功能

src/app.ts中添加 Taro.showShareMenu

class App extends Component {
    render() {
        Taro.showShareMenu({
            withShareTicket: true,
            // @ts-ignore
            menus: ['shareAppMessage', 'shareTimeline'],
            showShareItems: ['shareAppMessage', 'shareTimeline'],
        });

        // this.props.children 是將要會(huì)渲染的頁面
        return this.props.children
    }
}
5、引導(dǎo)關(guān)注公眾號(hào)
  • OfficialAccount
  • 關(guān)注/查看
import { OfficialAccount } from '@tarojs/components'
<OfficialAccount />

視圖

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

6、獲取用戶頭像/昵稱
  • Taro.getUserProfile 獲取用戶的頭像昵稱
  • Taro.setStorageSync 存儲(chǔ)信息 相當(dāng)于 localStorage.setItem
  • Taro.getStorageSync 獲取信息 相當(dāng)于 localStorage.getItem
getUserProfile() {
    Taro.getUserProfile({
        desc: '獲取用戶昵稱、頭像',
        success: (res) => {
            Taro.setStorageSync('userInfo', res.userInfo)
            this.setState({ userInfo: res.userInfo })
        },
        fail: () => {
            console.error("您拒絕了請求");
            return;
        }
    })
}

打印 getUserProfile success(res)

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

7、 封裝 WebView 實(shí)現(xiàn)跳轉(zhuǎn)公眾號(hào)內(nèi)頁
封裝的webview組件
  • getCurrentInstance 獲取地址欄/router
import { FC, useEffect, useState } from 'react'
import { View, WebView } from '@tarojs/components'
import { getCurrentInstance } from '@tarojs/taro'

const MyWebView: FC = () => {
    const [hrefURL, setHrefURL] = useState<string>('')

    useEffect(() => {
        const { params } = getCurrentInstance().router ?? {}
        setHrefURL(decodeURIComponent(params?.webUrl ?? ''))
    }, [])

    return (
        <View className='webview' >
            <WebView src={hrefURL} />
        </View>
    )
}
export default MyWebView

打印 getCurrentInstance()

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

相關(guān)頁面使用時(shí)

跳轉(zhuǎn)的公眾號(hào)需要是企業(yè)認(rèn)證的,才能配置業(yè)務(wù)域名,個(gè)人公眾號(hào)暫不支持WebView

handleGridClick(item: itemDTO) {
    Taro.navigateTo({ url: `/pages/webview/index?webUrl=${encodeURIComponent(item.url)}` })
}

跳轉(zhuǎn)

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

8、ScrollView視圖容器組件
  • Taro.getSystemInfoSync() 獲取設(shè)備屏幕高度
  • 設(shè)置 scrollY、height
  • scroll-view視圖容器組件各屬性含義
const { windowHeight } = Taro.getSystemInfoSync()
const scrollHeight = (windowHeight * windowHeight / 750 - 140)
const scrollStyle = {
    height: scrollHeight + 'px',
}

<ScrollView
    scrollY
    enhanced={true}
    show-scrollbar={false}
    scrollWithAnimation={true}
    enable-back-to-top={true}
    style={scrollStyle}
>
    // ...
</ScrollView>

打印 getSystemInfoSync()

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

9、數(shù)據(jù)可視化
  • git clone echarts-for-weixin
  • ec-canvas拷貝到自己項(xiàng)目中src下
  • 需要給 canvas設(shè)置寬高

需要在 index.config.ts聲明ec-canvas組件

export default {
    navigationBarTitleText: '前端進(jìn)階技術(shù)棧',
    usingComponents: {
        "ec-canvas": "../../ec-canvas/ec-canvas"
    }
}

index.ts 使用

function getPieChart(canvas, width, height, dpr) {
    const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr // 像素
    });
    canvas.setChart(chart);

    var option = {
        tooltip: {
            show: true
        },
        legend: {
            top: 'bottom'
        },
        series: [
            {
                name: 'Nightingale Chart',
                type: 'pie',
                radius: [35, 110],
                center: ['50%', '50%'],
                roseType: 'area',
                itemStyle: {
                    borderRadius: 8
                },
                data: [
                    { value: 56.7, name: 'Vue' },
                    { value: 36.4, name: 'Angular' },
                    { value: 72.5, name: 'React' }
                ]
            }
        ]
    }
    chart.setOption(option);
    return chart;
}
// ...
this.state = {
    ecPie: {
        onInit: getPieChart
    }
}
// ...

<View className="canvas pie">
    <ec-canvas id="mychart-dom-pie" canvas-id="mychart-pie" ec={ecPie}></ec-canvas>
</View>

在 global.d.ts 中添加以下內(nèi)容

declare namespace JSX {
    interface IntrinsicElements {
        'ec-canvas': any,
        ...
    }
}

視圖

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

EChart 相關(guān)文檔

  • echarts-for-weixin
  • EChart相關(guān)示例
  • EChart中options各屬性用法示例
  • 定制需要的圖表類型
10、集成Markdown
  • git clone wemark
  • wemark 文件拷貝到自己的項(xiàng)目的src目錄下
使用前配置

設(shè)置編譯時(shí)復(fù)制wemark目錄,修改config/index.js,在copy設(shè)置項(xiàng)中增加wemark,

copy: {
  patterns: [
    {
      from: 'src/wemark',
      to: 'dist/wemark',
    },
  ],
  options: {
  }
},

設(shè)置taro編譯時(shí)忽略 remarkable.js,繼續(xù)修改config/index.js

weapp: {
  compile: {
    exclude: [
      'src/wemark/remarkable.js',
    ]
  },
  ...
}

在 global.d.ts 中添加以下內(nèi)容

declare namespace JSX {
    interface IntrinsicElements {
        'wemark': any
    }
}
封裝Markdown文章詳情
import { FC, useEffect, useState } from 'react'
import { View } from '@tarojs/components'
import { getCurrentInstance } from '@tarojs/taro'
import './index.scss'
import Taro from '@tarojs/taro'

const Article: FC = () => {
    const [markdown, setMarkdown] = useState<string>('')

    useEffect(() => {
        const { md, title } = getCurrentInstance().router?.params ?? {}
        setMarkdown(decodeURIComponent(md ?? ''))
        Taro.setNavigationBarTitle({
            title: decodeURIComponent(title ?? '前端進(jìn)階技術(shù)棧')
        })
    }, [])

    return (
        <View className='article'>
            <wemark md={markdown} link={true} highlight={true} type='wemark' />
        </View>
    )
}
export default Article
視圖

Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序

11、調(diào)試打包上傳

web端調(diào)試

  • yarn dev:h5 web端調(diào)試

微信內(nèi)置 API 需要小程序開發(fā)工具調(diào)試文章來源地址http://www.zghlxwxcb.cn/news/detail-441678.html

  • yarn build:weapp
  • 微信開發(fā)者工具 引入 dist文件夾即可

到了這里,關(guān)于Taro + React + TS + Taro-UI + ECharts + Markdown 開發(fā)微信小程序的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(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)文章

  • taro開發(fā)微信小程序禁止下拉刷新(ios下拉出現(xiàn)空白問題)

    一、問題描述 最近用tarojs在做一個(gè)小程序項(xiàng)目時(shí),首頁需要禁止下拉刷新,于是在page.json里面添加了這段話 \\\"enablePullDownRefresh\\\":false 全局關(guān)閉下拉刷新,這段話確實(shí)禁止了下拉刷新,無論是安卓手機(jī)端還是蘋果端,但是在蘋果端卻出現(xiàn)了一個(gè)問題,整個(gè)頁面雖然不能下拉刷新

    2024年02月13日
    瀏覽(21)
  • 第一個(gè)微信小程序 Taro + React

    第一個(gè)微信小程序 Taro + React

    新建一個(gè)文件夾,在該文件夾下打開cmd,執(zhí)行命令 然后新建一個(gè)taro項(xiàng)目 基本上一路回車就可以,可參考下面的選項(xiàng) 打開idea,open該項(xiàng)目 安裝依賴 運(yùn)行小程序

    2024年02月13日
    瀏覽(23)
  • 【taro react】---- 解決開發(fā)環(huán)境微信小程序由于主包體積過大不能預(yù)覽問題

    【taro react】---- 解決開發(fā)環(huán)境微信小程序由于主包體積過大不能預(yù)覽問題

    1. 開發(fā)環(huán)境代碼包大小 注意:可以看到此時(shí)主包加分包將近 5MB,上傳預(yù)覽將會(huì)超出限制!??! 2. 預(yù)覽結(jié)果 報(bào)錯(cuò):代碼包大小超過限制,主包資源近3MB,限制最大2MB?。?! 3. 解決辦法 使用webpack的壓縮插件,在開發(fā)環(huán)境編譯的時(shí)候進(jìn)行壓縮; 進(jìn)行分包處理,同時(shí)依賴也進(jìn)行

    2024年02月10日
    瀏覽(36)
  • 關(guān)于在微信小程序中使用taro + react-hook后銷毀函數(shù)無法執(zhí)行的問題

    關(guān)于在微信小程序中使用taro + react-hook后銷毀函數(shù)無法執(zhí)行的問題

    問題: 在 taro中使用navigageTo() 跳轉(zhuǎn)路由后hook中useEffect 的return函數(shù)沒有執(zhí)行 沒有執(zhí)行return函數(shù) 框架版本: ?????tarojs:? 3.6? ? ????????????????????????react:? ?18.0? ? 原因: 使用navigateTo() 跳轉(zhuǎn)路由的話并不會(huì)銷毀頁面和組件,會(huì)加入一個(gè)最大數(shù)量為十層的路由

    2024年01月24日
    瀏覽(30)
  • 基于Taro + React 實(shí)現(xiàn)微信小程序半圓滑塊組件、半圓進(jìn)度條、弧形進(jìn)度條、半圓滑行軌道(附源碼)

    基于Taro + React 實(shí)現(xiàn)微信小程序半圓滑塊組件、半圓進(jìn)度條、弧形進(jìn)度條、半圓滑行軌道(附源碼)

    1、四個(gè)檔位 2、可點(diǎn)擊加減切換檔位 3、可以點(diǎn)擊區(qū)域切換檔位 4、可以滑動(dòng)切換檔位 給大家提供一些實(shí)現(xiàn)思路,找了一圈,一些文章基本不能直接用,錯(cuò)漏百出,代碼還藏著掖著,希望可以幫到大家 ts的寫法風(fēng)格 index.tsx? ? ? index.module.less 防抖的工具函數(shù)debounce 的詳細(xì)代碼

    2024年02月06日
    瀏覽(58)
  • 【taro react】---- 解決 iOS 真機(jī)微信小程序 Input 密碼框 type 切換會(huì)導(dǎo)致 Input 內(nèi)容丟失問題

    1. 問題場景 在密碼登陸時(shí),有顯示和隱藏密碼的功能,實(shí)現(xiàn)方式很簡單,直接對(duì)輸入 input 的 type 進(jìn)行 password 和 text 值進(jìn)行切換,就可以實(shí)現(xiàn)密碼的顯示和隱藏。 2. 實(shí)現(xiàn)代碼 通過修改 input 的 type 值實(shí)現(xiàn)密碼的顯示和隱藏。 密碼的顯示和隱藏控制圖標(biāo)也是通過 type 值進(jìn)行判斷

    2024年02月03日
    瀏覽(20)
  • taro vue3 ts nut-ui 項(xiàng)目

    taro vue3 ts nut-ui 項(xiàng)目

    查看 Taro 全部版本信息? 可以使用? npm info ?查看 Taro 版本信息,在這里你可以看到當(dāng)前最新版本 使用命令創(chuàng)建模板項(xiàng)目: taro init 項(xiàng)目名 微信小程序自定義 TabBar 先安裝 cnpm install pinia 以便解決 小程序的 頁面首次加載 在?app.config.js 中設(shè)置 在? src 目錄 下 pages 文件夾,在里

    2024年02月06日
    瀏覽(43)
  • 記錄 wx-open-launch-weapp 使用react開發(fā)微信環(huán)境h5打開微信小程序

    記錄 wx-open-launch-weapp 使用react開發(fā)微信環(huán)境h5打開微信小程序

    準(zhǔn)備工作? 1、微信簽名配合后端 2、必須已認(rèn)證的公眾號(hào)(開發(fā)模擬器不行,測試號(hào)不行) 遇見的問題: 本地調(diào)試麻煩,用的手機(jī)修改dns,和電腦一致,通過電腦代理,編譯時(shí)配置host代理運(yùn)行調(diào)試(因?yàn)楸镜亻_發(fā)沒辦法簽名認(rèn)證) 1、在微信編輯器,測試號(hào)內(nèi)怎么試都不生效,最后發(fā)現(xiàn)正式

    2024年02月16日
    瀏覽(21)
  • 使用uni-ui 實(shí)現(xiàn)下拉搜索框(uniapp+uni-ui+vue3 開發(fā)微信小程序)

    需求:輸入框中輸入內(nèi)容--遠(yuǎn)端搜索匹配的選項(xiàng)--展示選項(xiàng)(可點(diǎn)擊選擇選項(xiàng)) 代碼實(shí)現(xiàn) htm:(一個(gè)輸入框input + list) js: css

    2024年01月24日
    瀏覽(20)
  • Taro+Vue3 小程序引入echarts表

    Taro+Vue3 小程序引入echarts表

    背景:根據(jù)需求在一個(gè)報(bào)告界面需要展示不同的echarts表來使數(shù)據(jù)更友好的顯示。 效果如下: 一.taro支持echarts 官方說明:Taro 文檔支持引用小程序端第三方組件庫 物料文檔:Taro 物料市場 | 讓每一個(gè)輪子產(chǎn)生價(jià)值 二.引入echarts-for-weixin插件 github地址: https://github.com/ecomfe/echar

    2024年02月13日
    瀏覽(22)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包