Small program problem handling

redirectTo and navigateTo can no longer jump to pages with tabs

The applet adds an interface wx.switchTab. This interface is specially used to jump to pages with tabbars

Page({
    onTap: function (event) {        
        wx.switchTab({
            url: "../posts/post"
        });

    }
})

Note that switchTab can only jump to pages with tabs, not pages without tabs! To jump to pages without tabs, you still need to use redirect or navigate! So, if your post page has not added a tab, please still use redirect or navigate!

In the onLoad function of Page, it is no longer possible to directly assign data to the data variable for data binding.

Use this.setData method to update data

Page({
  data: {
  },
  onLoad: function () {

    // this.data.postList = postsData.postList
    this.setData({
       postList:postsData.postList
      });
  },

Content-Type parameter of wx.request method

The earliest version uses content-type: application/json
Any form can be used, as long as it is not an empty string and application/json

function http(url, callBack) {
  wx.request({
    url: url,
    method: 'GET',
    header: {
      "Content-Type": "json"
    },
    success: function (res) {
      callBack(res.data);
    },
    fail: function (error) {
      console.log(error)
    }
  })
}

—Updated January 4, 2017 ——————————————

About the input component

In older versions, the input bindblur event did not respond to the carriage return event in the simulator.

But WeChat has secretly changed this rule. In the latest version 122100, bindblur can respond to carriage return events.

————————— 17.1.4 Update ———————————————

Version 122100 adds a bindconfirm event to the input event. It is no longer necessary to use the awkward bindchange or bindblur as the trigger event for keyboard completion, please use bindconfirm.

Script error or Page() is not called correctly" error message.

write picture description here
The reason for this error is usually because the Page method is not called in the js file of the corresponding page. Even if there is no code in the js file, you need to add an empty Page ({ }) in the js. Note that Page's P should be capitalized.

Why do I get the error message "Expecting 'String, 'Number, 'NULL, 'True...'"''?

write picture description here

The reason for this error is that { } is not added to the json file of the corresponding page. Even if there is nothing in the json file, you need to add a { } as the default code. The json file does not allow commented code. If there is commented code, this error will also be reported.

出现“ Failed to load image http://2110932784.debug.open.weixin.qq.com/pages/posts/images/post/crab.png : the server responded with a status of 404 (HTTP/1.1 404 Not Found) From server 127.0.0.1”

write picture description here

(The question is raised and organized from Zhihu ID: stubborn master) Similar errors are usually caused by the wrong path of the picture. We won't talk about the pictures of the external network here, because there is no relative and absolute path concept, if the error is reported, the picture url of your external network is wrong. Let's talk about the local image path problem. Note that if the image path is written in a js file A, and B references the js file, the image path must be a relative path relative to B. Therefore, it is better to use absolute paths in public js files.
Another point is to remind everyone that the applet has a cache for resource files, such as pictures, and everyone should pay attention to this.

Why does "Missing file, error message: error:iconPath=.......file not found?" appear when previewing on real machine

write picture description here

In the development tool -> project -> preview, sometimes the above error will be reported. The reason for the error is because, in the tabBar option of app.json, the iconPath under list has an absolute path " / ", such as

"list": [{
      "pagePath": "pages/movies/movies",
      "iconPath": "/images/tab/dianying.png",
      "selectedIconPath": "images/tab/dianying_hl.png",
      "text": "电影"
    }, {
        "pagePath": "pages/setting/setting",
        "iconPath": "/images/tab/set.png",
        "selectedIconPath": "images/tab/set_hl.png",
        "text": "设置"
      }],

The above error occurs when iconPath starts with "/ ". Please use relative paths without the / .

Regarding the warning message "Now you can provide attr "wx:key" for a "wx:for" to improve performance".

write picture description here

First of all, this is just a warning message, not an error message, ignoring it will not have any effect on the program running. Second, this is new in version 112300. The reason why it is not dealt with in the course is that adding wx:key to the static article list with only 5 pieces of data does not make any sense. wx:key is used to specify a "primary key" for the data rendered in the list to speed up the rendering of the list. The following are the original words of the official document: If wx:key is not provided, a warning will be reported. If you know that the list is static, or you don't need to pay attention to its order, you can choose to ignore it.
If you absolutely want to remove this warning, you can add a wx:key=”unique” to the component property of wx:for, replace unique with the field name of any field in the data binding list, such as in the article list data Field "postId", ie wx:key="postId". wx:key=”*this” is deprecated. .

I get the error please do not register multiple Pages in undefined.js.

write picture description here
This is probably the addition of Page() in app.js. app.js is an application level that cannot be used with Page(), and Page*() can only be used in the js file of the page. app.js please use App().

Can't display the picture on the real machine using background-image?

background-image If the url points to a network image, the real machine can display it. But if the url points to a local image, it will display normally in the simulator, but the image cannot be displayed on iOS. It is recommended to use image.

The above questions are from the Zhihu column https://zhuanlan.zhihu.com/oldtimes?topic=%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F

More learning materials
https://github.com/7insummer/orange-can
https://github.com/7insummer/orange-can-server

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325225912&siteId=291194637