按照官方文檔,除了要在app.json中先聲明這個組件之外,還需要再使用頁面引入toast。
"usingComponents": {
"van-toast": "@vant/weapp/toast/index"
}
官網引入方式寫的爲:import Toast from 'path/to/@vant/weapp/dist/toast/toast';
但是,運行小程序會報錯:
module "pages/index/path/to/@vant/weapp/dist/toast/toast" is not defined
Error: module "pages/index/path/to/@vant/weapp/dist/toast/toast" is not defined
如下圖:
所以經過嘗試,得出結論上面的"path/to"不可以直接寫,意思要轉換爲自己toast.js的本地路徑:
嘗試過後引入方式爲:
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'