小程式使用自定義元件報錯Component is not found in path “components
寫完小元件之後執行報錯(
元件json("component": true)和引用元件頁面json都按規範寫沒有問題,js沒有問題,編譯沒有問題的情況下)啥問題沒有就是報錯:
Error: Component is not found in path “components /my_toast/my_toast” (using by "pages"/index/index)
index頁面的路徑是 miniprogram/pages/index/index
my_toast元件的路徑是 miniprogram/components/my_toast/my_toast (解決後路徑)
報錯位置是:my_toast.json
1 {
2 "usingComponents":{
3 "error_toast":"../../components/my_toast/my_toast"
4 }
5 }
解決方案:
1)使用公眾開放平臺註冊的小程式(非開發工具上的“小程式”,“小遊戲”,demo)根據AppID 開啟會自動建立
cloudfunctions ; mineprogram 目錄,新建 component 需要在 mineprogram目錄下建立,不可以與mineprogram同級
2)檢查路徑
編寫正確路徑:相對路徑和絕對路徑 (取自:https://zhidao.baidu.com/question/54621865.html @awerlasdfwe )
Linux :右斜槓(' / ')Windows:左斜杆(' \ ')
絕對路徑:是從碟符開始的路徑,形如
C:\windows\system32\cmd.exe
要描述上述路徑,只需輸入
system32\cmd.exe
實際上,嚴格的相對路徑寫法應為
.\system32\cmd.exe
其中,.表示當前路徑,在通道情況下可以省略,只有在特殊的情況下不能省略。
假如當前路徑為c:\program files
要呼叫上述命令,則需要輸入
..\windows\system32\cmd.exe
其中,..為父目錄。
當前路徑如果為c:\program files\common files
則需要輸入
..\..\windows\system32\cmd.exe
另外,還有一種不包含碟符的特殊絕對路徑,形如
\windows\system32\cmd.exe
無論當前路徑是什麼,會自動地從當前盤的根目錄開始查詢指定的程式。
之前元件名 :toast (這是一個彈窗提示)
問題:
執行後發現彈出是wx.toast ,而非我的自定義元件
原因:
元件名不能與wx元件衝突
解決:
重新命名:my_toast