我们搜到的教程都是说从vant-weapp的git仓库中下载源码,拷贝dist目录到我们创建的mpvue项目文件的static或者dist或者…文件夹中,我觉得都可以吧,只是涉及你引用组件时的路径怎么写。

这里把vant-weapp的dist目录重命名为vant-weapp放在项目根目录的static文件夹下:


在src文件夹下,即我们写vue代码的位置,正在编写的页面中添加main.json文件(vue代码编译成小程序代码时会直接使用这个文件):

{
  "usingComponents": {
    "van-button": "/static/vant-weapp/button/index"        
    //这个路径是指根目录下static文件中...
  }
}

ps: 我在app.json中引入, 即可全局使用

{
  "pages": [
    "pages/index/main",
    "pages/logs/main",
    "pages/counter/main"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle": "black"
  },
  "tabBar": {
    "color": "#999",
    "backgroundColor": "#fafafa",
    "selectedColor": "#333",
    "borderStyle": "white",

    "list": [{
      "text": "首页",
      "pagePath": "pages/index/main",
      "iconPath": "static/tabs/home.png",
      "selectedIconPath": "static/tabs/home-active.png"
    }, {
      "text": "订单",
      "pagePath": "pages/logs/main",
      "iconPath": "static/tabs/orders.png",
      "selectedIconPath": "static/tabs/orders-active.png"
    }],

    "items": [{
      "name": "首页",
      "pagePath": "pages/index/main",
      "icon": "static/tabs/home.png",
      "activeIcon": "static/tabs/home-active.png"
    }, {
      "name": "订单",
      "pagePath": "pages/logs/main",
      "icon": "static/tabs/orders.png",
      "activeIcon": "static/tabs/orders-active.png"
    }],
    "position": "bottom"
  },
  "usingComponents": {
    "van-action-sheet": "/static/vant/action-sheet/index",
    "van-area": "/static/vant/area/index",
    "van-badge": "/static/vant/badge/index",
    "van-badge-group": "/static/vant/badge-group/index",
    "van-button": "/static/vant/button/index",
    "van-card": "/static/vant/card/index",
    "van-cell": "/static/vant/cell/index",
    "van-cell-group": "/static/vant/cell-group/index",
    "van-checkbox": "/static/vant/checkbox/index",
    "van-checkbox-group": "/static/vant/checkbox-group/index",
    "van-col": "/static/vant/col/index",
    "van-dialog": "/static/vant/dialog/index",
    "van-field": "/static/vant/field/index",
    "van-goods-action": "/static/vant/goods-action/index",
    "van-goods-action-icon": "/static/vant/goods-action-icon/index",
    "van-goods-action-button": "/static/vant/goods-action-button/index",
    "van-icon": "/static/vant/icon/index",
    "van-loading": "/static/vant/loading/index",
    "van-nav-bar": "/static/vant/nav-bar/index",
    "van-notice-bar": "/static/vant/notice-bar/index",
    "van-notify": "/static/vant/notify/index",
    "van-panel": "/static/vant/panel/index",
    "van-popup": "/static/vant/popup/index",
    "van-progress": "/static/vant/progress/index",
    "van-radio": "/static/vant/radio/index",
    "van-radio-group": "/static/vant/radio-group/index",
    "van-row": "/static/vant/row/index",
    "van-search": "/static/vant/search/index",
    "van-slider": "/static/vant/slider/index",
    "van-stepper": "/static/vant/stepper/index",
    "van-steps": "/static/vant/steps/index",
    "van-submit-bar": "/static/vant/submit-bar/index",
    "van-swipe-cell": "/static/vant/swipe-cell/index",
    "van-switch": "/static/vant/switch/index",
    "van-switch-cell": "/static/vant/switch-cell/index",
    "van-tab": "/static/vant/tab/index",
    "van-tabs": "/static/vant/tabs/index",
    "van-tabbar": "/static/vant/tabbar/index",
    "van-tabbar-item": "/static/vant/tabbar-item/index",
    "van-tag": "/static/vant/tag/index",
    "van-toast": "/static/vant/toast/index",
    "van-transition": "/static/vant/transition/index",
    "van-tree-select": "/static/vant/tree-select/index",
    "van-datetime-picker": "/static/vant/datetime-picker/index",
    "van-rate": "/static/vant/rate/index",
    "van-collapse": "/static/vant/collapse/index",
    "van-collapse-item": "/static/vant/collapse-item/index",
    "van-picker": "/static/vant/picker/index"
  },
  "sitemapLocation": "sitemap.json"
}


然后就可以运行了:cmd->

npm run dev
 


接着打开微信开发者工具,会发现报错:


打开微信开发者工具的“详情”右侧栏,有一个ES6转ES5:


把这个“ES6转ES5”的选项勾上就不会报错了…出现vant-weapp的样式。

参考: https://blog.csdn.net/sinat_38783046/article/details/85638693

Logo

前往低代码交流专区

更多推荐