小程序开发历程

377 阅读1分钟

开始使用准备工作

安装(遇到情况可以访问官网)

npm install -g @tarojs/cli
taro init myApp
yarn
taro build --type swan --watch

taro-docs.jd.com/taro/docs/G…

使用

配置app.json
{
    "pages": [
      "pages/index/index",
      "pages/carsource/carsources",
    ],
    "tabBar": {
      "list": [{
        "pagePath": "pages/index/index",
        "text": "首页"
      }, {
        "pagePath": "pages/carsource/carsources",
        "text": "车源"
      }]
    }
  }
app.js 的基本配置
import Taro, { Component, Config } from '@tarojs/taro'
import Index from './pages/index/index'
import './app.scss'


class App extends Component {
  componentDidMount () {}
  
  config: Config = {
    pages: [
      'pages/index/index',
      "pages/carsource/carsources",
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    },
    tabBar:{
      selectedColor: "#56d2bf",
      list:[{
        pagePath: "pages/index/index",
        iconPath: "static/images/shouye.png",
        selectedIconPath: "static/images/shouye_active.png",
        text: "首页"
      }
      ,{
        pagePath: "pages/carsource/carsources",
        iconPath: "static/images/shop.png",
        selectedIconPath: "static/images/shop.png",
        text: "车源"
      }
    ]

    }
  }
  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render () {
    return (
      <Index />
    )
  }
}

Taro.render(<App />, document.getElementById('app'))

过程中遇到的问题

根据 sitemap 的规则[0],当前页面 [pages/index/index] 将被索引

解决: 打开project.config.json,在setting中设置checkSiteMap的值为false,表示关闭该功能。

未找到 app.json 中的定义的 pages "pages/base/base" 对应的 WXML 文件

路由改为pages/base/base1即可,“base1”>文件名不要和文件夹名一致,就可以自动生成了