Vue, I pass a number, and I receive string?.

write a component by yourself, which is passed to the subcomponent as number, but the result subcomponent receives stringtype

.

parent component:

<cmsProgress num=40></cmsProgress>

Sub-component:

<el-progress :text-inside="true" :stroke-width="20" :percentage="num" color="red"></el-progress>

export default {
    props:["num"],
    data () {
        return {
            
        }
    },
    mounted:function(){
        console.log(typeof(this.num));  //string
    }
}

what is the reason for this?


this is why the HTML tag attribute value itself is the string . For more detailed interpretation, please refer to Portal

.

clipboard.png

so the code should be changed to the following:

<cmsProgress :num="40"></cmsProgress>

to get Number , follow @ Wenbo mentioned : num= "40" so

it's not really the vue problem, but any attributes in the html element itself will be parsed to string (even if you're not using vue ).

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a0fc-2c1e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a0fc-2c1e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?