秋霞步兵区国产精品,国产精品视频二区第二页,亚洲aⅴ欧美综合一区二区三区,亚洲日韩欧美一区二区不卡

      1. <small id="x8tpb"></small>
        <address id="x8tpb"></address>

        新疆信息港歡迎您!

        新疆信息港
        新疆信息港 > 資訊 >小程序開發(fā)神兵利器-Taro實戰(zhàn)-02!

        小程序開發(fā)神兵利器-Taro實戰(zhàn)-02!

        2020-11-20 09:16:47
        來源:互聯(lián)網(wǎng)
        閱讀:-

        '~config': path.resolve, />export default Index as ComponentType;至此我們的第一個頁面已經(jīng)展示在我們面前了,下一期我將繼續(xù)和大家分享,后端基本框架的搭建,以及數(shù)據(jù)庫的設計。...

        寫在前面

        上一篇文章我們運行了第一個helloworld程序,為了后續(xù)功能開發(fā),我們需要對目錄結構進行相應的改造,并完成第一個頁面的結構部分。

        項目改造

        taro配置修改

        這一步的目的是為了以后為小程序云開發(fā)留出余地,修改的同時別忘了將miniprogram放到.gitignore中

        項目根目錄下創(chuàng)建app文件夾,將項目根目錄下的project.config.json移動到app目錄下

        并修改 project.config.json

        # 將"miniprogramRoot": "./dist",# 修改為"miniprogramRoot": "miniprogram/",

        修改config/index.js

        # 將outputRoot: 'dist'# 修改為outputRoot: 'app/miniprogram'# 添加別名,在后續(xù)開發(fā)中直接使用別名導入模塊alias: {    '~assets': path.resolve(__dirname, '..', 'src/assets'),    '~services': path.resolve(__dirname, '..', 'src/services'),    '~components': path.resolve(__dirname, '..', 'src/components'),    '~styles': path.resolve(__dirname, '..', 'src/styles'),    '~config': path.resolve(__dirname, '..', 'src/config'),    '~store': path.resolve(__dirname, '..', 'src/store'),    '~utils': path.resolve(__dirname, '..', 'src/utils'),    '~schema': path.resolve(__dirname, '..', 'src/schema'),}

        tsconfig.json修改

        compilerOptions: {    ...,    # 添加    "paths": {        "~assets/*": ["src/assets/*"],        "~components/*": ["src/components/*"],        "~config/*": ["src/config/*"],        "~store/*": ["src/store/*"],        "~styles/*": ["src/styles/*"],        "~utils/*": ["src/utils/*"],        "~services/*": ["src/services/*"],        "~pages/*": ["src/pages/*"],        "~schema/*": ["src/schema/*"]    }}

        添加一些文件夾

        src/目錄下,文件結構修改

        ├── assets # 存放靜態(tài)資源,如圖片等├── components # 存放通用組件├── config # 存放程序配置文件├── pages├── schema # 存放數(shù)據(jù)結構定義文件├── services # 訪問網(wǎng)絡訪問方法├── store # 存放數(shù)據(jù)├── styles # 存放全局樣式├── subPages # 分包└── utils # 存放工具方

        添加一些常用的庫

        yarn add dayjs # moment 太大了,所以選擇了dayjsyarn add decimal.js # 后面會有一些計算,提前先引入了yarn add lodash # 用習慣了雖然很多功能原生都能寫了,但是還是喜歡它一點yarn add mobx-utils # mobx的一些工具庫還是很不錯的,必自己寫來的方便yarn add taro-ui # taro的ui庫——懶人的邏輯就是能用成熟的絕不自己寫

        開發(fā)者工具選擇項目剛才新建的app目錄導入項目


        第一個組件

        新建文件 /src/components/chunk/index.tsx

        這個組件現(xiàn)在的功能很簡單,之所以抽出來單獨寫,主要是為了演示組件一般情況下是什么樣子

        import Taro, { Component } from '@tarojs/taro';import { View } from '@tarojs/components';import { CSSProperties } from 'react';interface ChunkProps {  style?: CSSProperties;}interface ChunkState {}class Chunk extends Component {  render() {    const { children, style } = this.props;    return (              {children}          );  }}export default Chunk;

        第一個頁面

        src/pages/index/index.scss

        page {    background: #ecedee;  }  .home {    padding: 0rpx 30rpx;    .header {        margin-top: 60rpx;        width: 100%;        background-repeat: no-repeat;        background-size: cover;        background-position: center;    }}

        src/pages/index/index.tsx

        import { ComponentType } from 'react';import Taro, { Component, Config } from '@tarojs/taro';import { View, Image, Navigator, Text } from '@tarojs/components';import Chunk from '~components/chunk';import './index.scss';interface IndexProps {}class Index extends Component {  config: Config = {    navigationBarTitleText: '攢局',    enablePullDownRefresh: true,    navigationBarBackgroundColor: '#ecedee',    backgroundColor: '#ecedee',  };  render() {    return (                                                  共攢了                              0                            個局                                                    {0}                                                                      攢局記錄                                                            去提現(xiàn)                                                                                                                      攢局                報名活動,自動統(tǒng)計,簡單高效                                                                    );  }}export default Index as ComponentType;


        小程序開發(fā)神兵利器-Taro實戰(zhàn)-02


        至此我們的第一個頁面已經(jīng)展示在我們面前了,下一期我將繼續(xù)和大家分享,后端基本框架的搭建,以及數(shù)據(jù)庫的設計。

        推薦閱讀:中國融合網(wǎng)

        免責聲明:本文僅代表企業(yè)觀點,與新疆信息港無關。其原創(chuàng)性以及文中陳述文字和內(nèi)容未經(jīng)本站證實,對本文以及其中全部或者部分內(nèi)容、文字的真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,并請自行核實相關內(nèi)容。
        熱門圖片
        熱門搜索