mpvue項目使用第三方UI框架vant weapp

我們搜到的教程都是說從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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章