WeChat Mini Programs selectcomponent returned null, and could not get registration.

clipboard.png

clipboard.png

clipboard.png

clipboard.png

index.wxml

<!--  -->
<dialog id="dialog" bind:cancelEvent="cancelEvent" bind:okEvent="okEvent"></dialog>

index.js Code

onReady: function () {
    //dialog
    this.dialog = this.selectComponent("-sharpdialog");
},
//
tapDialog: function () {
    this.dialog.setData({
        title: "",
        content: "",
        cancelText: "",
        okText: ""
    });
    this.dialog.show();
},

cancelEvent: function () {
    console.log(this.dialog.data.cancelText);
    this.dialog.close();
},

okEvent: function () {
    var that = this
    console.log(this.dialog.data.okText);
    //
    // wx.openSetting({
    //     success(res) {
    //         console.log(res);
    //         that.dialog.close();
    //         qqmap.getLocateInfo().then(data => {
    //             wx.setStorage({
    //                 key: "city",
    //                 data: {
    //                     name: data[0],
    //                     latitude: data[1],
    //                     longitude: data[2],
    //                 },
    //             })
    //             qqmap.calculateDistance().then(data => {
    //                 if (data != "") {
    //                     that.setData({
    //                         isLocation: true,
    //                         distanceText: "" + data
    //                     })
    //                     app.globalData.isLocation = true
    //                     app.globalData.distanceText = "" + data
    //                 } else {
    //                     that.setData({
    //                         isLocation: false,
    //                         distanceText: ""
    //                     })
    //                     app.globalData.isLocation = false
    //                     app.globalData.distanceText = ""
    //                 }
    //             })
    //         })
    //     }
    // })
},
//
clickLoaction: function () {
    if (this.data.isLocation == false) {
        this.tapDialog()
    }
}
component files are normal, applied to other pages can be registered successfully, only put on the home page to report an error, the component can not register successfully, ask God for help!

this.dialog = this.selectComponent ('- sharpdialog'); , the component has not been rendered yet when running onReady. Do not put it in onReady, try it in tapDialog

.
Menu