Tag Archives: WeChat applet

uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigu

1. Background

I found this error when developing wechat applet with uniapp, and recorded how I solved it!

2. Error message

uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigurable property.”

3. Error reason:

Because in the Object.defineproperty method, the control property cannot be deleted. It is in an unconfigurable state.

4. Error analysis

Let’s take a look at the specific use of the Object.defineproperty method:

The role of Object.defineproperty is to define a new property directly on an object, or modify an existing property

Object.defineproperty parameter

The Object.defineproperty method needs to pass 3 parameters

Object.defineproperty(obj, prop, desc)

Parameter 1: obj The current object whose properties need to be defined

Parameter 2: prop The name of the property that currently needs to be defined

Parameter 3: The desc descriptor is generally an object

Generally, by assigning a value to the property of the object, the property of the object can be modified or deleted, but the property of the object can be defined by Object.defineProperty(), and the property of the object can be controlled more precisely by the setting of the descriptor.

Object.defineProperty(obj, variate, {
                enumerable:true, //Controls whether the property can be enumerated, the default value is false
                 //writable:true, //Whether the control property can be modified, the default value is false
                 configurable:true, //Control whether the property can be deleted, the default value is false
                set: function (value) {
                    console.log('global set value!');
                    val = value; 
                    const data = {};
                    data[variate] = value;
                    console.log('page set value!');
                    page.setData(data);
                },
                get: function () {
                    console.log('global get value!');
                    // This will be executed when getApp().globalData.variate is called in other interfaces.
                     return val; // return the current value
                }
            });

Finally, there are two most important attributes, set and get (that is, accessor Description: define how attributes are accessed). What are these two attributes used for?

Note: when getter or setter methods are used, writable and value attributes are not allowed (if used, an error will be reported directly)

5. Solution

This error is caused by the value of configurable being set to false, so it can be changed to true! Pay attention to the error prompt on the console. Maybe your error is reported in other situations!

[Solved] JSON.parse() Error: Unexpected end of JSON input

Error returned during JSON.parse() conversion due to conversion characters or other special characters in the data of the converted JSON.stringify().

Solution:

encoding before the JSON.stringify() transformation and decoding the operation when JSON.parse() is solved.

Example:

Jump pass parameter

 toEdit() {
    this.data.userInfo.faceData = this.data.faceData
    let info = encodeURIComponent(JSON.stringify(this.data.userInfo))
    wx.navigateTo({
      url: '../userEdit/userEdit?info=' + info 
    })
  },

receive data

onLoad(options) {
	//decodeURIComponent decoding
   let info = JSON.parse(decodeURIComponent(options.info))
   this.setData({info:info})
}

Vant weapp uses the dialog pop-up box to prompt for path error

When writing wechat applet, use the dialog pop-up box of the third-party vant web to prompt the path error

But it is used according to the official tips

  After repeated modification, the path still reports an error. According to the hierarchy, the path is no problem

 

  The problem of path error will still be reported!

  Finally, after repeated attempts, the package/dist needs to be removed and can be used normally

 

Syntaxerror: unexpected end of JSON input [How to Solve]

Onload executes only once
SetData stores data in the page cache
if the data is undefined, you may need that = this. After the curly braces, the of these changes
e in the event function is an event, which refers to the event of this operation
options are objects.

If it is written like this, an error will be reported: syntax error: unexpected end of JSON input

At this time, do not use the arrow function!

So there is no error!

Wechat program typeerror: a solution to cannot read property ‘SetData’ of undefined

Questions

In the custom click event function, there is an error calling SetData, indicating that it is undefined

reason

The current this refers to the instance object of the success function

delTaskTap(e){
    wx.showModal({
      title:'Tips',
      content:'Do I have to clear all my to-do lists?',
      success:function(res){
        if(res.confirm){
          this.setData({
            taskText:[]
          })
          console.log('Clear all to-do items')
        }
        else if(res.cancel){
          console.log('Not clearing all to-do items')
        }
      }
    })

terms of settlement

delTaskTap(e){
    var that=this
    wx.showModal({
      title:'Tips',
      content:'Do I have to clear all my to-do lists?',
      success:function(res){
        if(res.confirm){
          that.setData({
            taskText:[]
          })
          console.log('Clear all to-do items')
        }
        else if(res.cancel){
          console.log('Not clearing all to-do items')
        }
      }
    })

Cloud init error: error: invalid scope does not have permission

Confirm that the env cloud environment parameters you have configured are correct, and report the following error after compiling. The reason is that appid needs to wait about 10 minutes for the official background to prepare for the service after opening the cloud environment for the first time, and then it can be compiled again after 10 minutes.

Using uniapp uni.downloadFile Download picture to photo album times error unknown problem

Suppose we upload a JPG image. When we upload using OSS, if we specify that the content type is image/jpeg, the generated outer chain will be displayed directly on the browser. If the set content type is application/octet stream or multipart/form data, the external link is downloaded directly. In the final analysis, the content type in the response header indicates what type the browser is, rather than judging by the URL suffix jpg

First of all, you need to pay attention to the type of image to download. Content type is image/jpeg type. If it is image/JPG type, it may lead to the problem of unknown