小程序使用自定义组件报错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
        相对路径:是从当前路径开始的路径,假如当前路径为C:\windows
        要描述上述路径,只需输入
        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

猜你喜欢

转载自blog.csdn.net/qq_35629609/article/details/83272090