WeChat applet - the difference between " " and "{{ }}" when passing value

MyBtn.js
Component({
    properties:{
        btnName:{
            type:String,
            value:"默认btn"
        },
        num:Number,
        arr:Array
    },
    created(){
        console.log(1000)
        console.log(this.data)
        console.log(typeof this.data)
    }
})

MyBtn.wxml

<button style="background: red;color: #fff;">
    {
   
   {btnName}} {
   
   {num}} {
   
   {arr}}
</button>
hello.wsml
<!--pages/hello/hello.wxml-->
<text>{
   
   {msg}}</text>
<button bindtap="update">修改</button>
<my-btn btnName="{
   
   {'我的按钮'}}"></my-btn>
<!-- <my-btn btnName="按钮2" num="3.14" arr="[1,2,3]"></my-btn> -->
<my-btn btnName="按钮2" num="{
   
   {3.14}}" arr="{
   
   {[1,2,3]}}"></my-btn>
renderings

 

When using "" directly for an array, the following warning appears.

This error message indicates that the arr attribute in the MyBtn component received an incompatible value. This property expected an array (<Array>) but received a non-array value. To solve this problem, you can check the value of the arr attribute passed to the MyBtn component. Make sure you are passing an array.

When passing value, the information in " " will be converted into the defined type. Using " " means to force the string type to the defined type, and the system cannot force the string with [ ] to the defined array arr, so num can be displayed normally, but arr cannot.

Therefore, when you want to pass a typed parameter, use interpolation expression, that is, "{ { } }" form

Guess you like

Origin blog.csdn.net/weixin_58963766/article/details/131620057