最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

簡單理解vue中Props屬性

 更新時間:2021年04月12日 09:59:03   作者:馬優(yōu)晨  
這篇文章主要幫助大家簡單的理解vue中Props屬性,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家解析了vue中Props的屬性,供大家參考,具體內(nèi)容如下

使用 Props 傳遞數(shù)據(jù)

組件實例的作用域是孤立的。這意味著不能并且不應(yīng)該在子組件的模板內(nèi)直接引用父組件的數(shù)據(jù)??梢允褂?props 把數(shù)據(jù)傳給子組件。

“prop” 是組件數(shù)據(jù)的一個字段,期望從父組件傳下來。子組件需要顯式地用 props 選項 聲明 props:

Vue.component('child', {
 // 聲明 props
 props: ['msg'],
 // prop 可以用在模板內(nèi)
 // 可以用 `this.msg` 設(shè)置
 template: '<span>{{ msg }}</span>'
})

然后向它傳入一個普通字符串:

<child msg="hello!"></child>

舉例

錯誤寫法:

<!DOCTYPE html>
<html lang="en">

<head>
 <script type="text/javascript" src="./vue.js"></script>
 <meta charset="UTF-8">
 <title>vue.js</title>
</head>

<body>
<pre>
 //使用 props 傳輸資料予子組件
 //props , data 重復(fù)名稱會出現(xiàn)錯誤


</pre>
<div id="app1">
 <child mssage="hello!"></child>
</div>
<script>
 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>{{ msg }}{{nihao}}{{nisha}}</span>',
 data: function() {
 return {
 mssage: 'boy'
 }
 }
 });
 var vm = new Vue({
 el: '#app1'
 })
</script>
</body>

</html>

正確寫法:

<!DOCTYPE html>
<html lang="en">

<head>
 <script type="text/javascript" src="./vue.js"></script>
 <meta charset="UTF-8">
 <title>vue.js</title>
</head>

<body>
<pre>
 //使用 props 傳輸資料予子組件
 //props , data 重復(fù)名稱會出現(xiàn)錯誤


</pre>
<div id="app1">
 <child mssage="hello!"></child>
</div>
<script>
 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>{{ msg }}{{nihao}}{{nisha}}</span>'
 });
 var vm = new Vue({
 el: '#app1'
 })
</script>
</body>

</html>

props 傳入多個數(shù)據(jù)(順序問題)

第一種:

HTML

<div id="app1">
<child msg="hello!"></child>
<child nihao="hello1!"></child>
<child nisha="hello2!"></child>
</div>

JS

 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>{{ msg }}{{nihao}}{{nisha}}</span>',
 /*data: function() {
 return {
 msg: 'boy'
 }
 }*/
 });
 var vm = new Vue({
 el: '#app1'
 })

結(jié)果:hello! hello1! hello2!

第二種:

HTML

<div id="app1">
<child msg="hello!"></child>
 <child nihao="hello1!"></child>
 <child nisha="hello2!"></child>
</div>

JS

 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>123{{ msg }}{{nihao}}{{nisha}}</span>',
 /*data: function() {
 return {
 msg: 'boy'
 }
 }*/
 });
 var vm = new Vue({
 el: '#app1'
 })

結(jié)果:123hello! 123hello1! 123hello2!

第三種:

HTML

<div id="app1">
<child msg="hello!"></child>
<child nihao="hello1!"></child>
 <child nisha="hello2!"></child>
</div>

JS

 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>{{ msg }}{{nihao}}{{nisha}}123</span>',
 /*data: function() {
 return {
 msg: 'boy'
 }
 }*/
 });
 var vm = new Vue({
 el: '#app1'
 })

結(jié)果:hello! 123 hello1! 123 hello2!123

第四種:

HTML

<div id="app1">
<child msg="hello!"></child>
<child nihao="hello1!"></child>
<child nisha="hello2!"></child>
</div>

JS

 Vue.config.debug = true;
 Vue.component('child', {
 // declare the props
 props: ['msg','nihao','nisha'],
 // the prop can be used inside templates, and will also
 // be set as `this.msg`
 template: '<span>{{ msg }}123{{nihao}}{{nisha}}123</span>',
 /*data: function() {
 return {
 msg: 'boy'
 }
 }*/
 });
 var vm = new Vue({
 el: '#app1'
 })

結(jié)果:hello! 123 123hello1! 123hello2!

結(jié)論:

在props 中傳入多個數(shù)據(jù)是,如果在父組件的模板類添加其他元素或者字符會有:
1-在最前面加入—每個子組件渲染出來都會在其前面加上

2-在最后面加入—每個子組件渲染出來都會在其后面加上

3-在中間加入—他前面子組件后面加上,后面的子組件后面加上

參考: http://cn.vuejs.org/guide/components.html#Props

本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。

關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解VUE響應(yīng)式原理

    詳解VUE響應(yīng)式原理

    這篇文章主要為大家介紹了vue組件通信的幾種方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • vue中動態(tài)組件使用及傳值方式

    vue中動態(tài)組件使用及傳值方式

    這篇文章主要介紹了vue中動態(tài)組件使用及傳值方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 前端axios取消請求總結(jié)詳解

    前端axios取消請求總結(jié)詳解

    這篇文章主要為大家介紹了前端axios取消請求總結(jié)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Vue.js計算屬性computed與watch(5)

    Vue.js計算屬性computed與watch(5)

    這篇文章主要為大家詳細(xì)介紹了Vue.js計算屬性computed與watch,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • vue項目頁面刷新404錯誤的解決辦法

    vue項目頁面刷新404錯誤的解決辦法

    在Vue.js項目中使用vue-router的history模式時,直接訪問或刷新頁面可能會導(dǎo)致404錯誤,文中通過代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定參考借鑒價值,需要的朋友可以參考下
    2024-11-11
  • Vue 實現(xiàn)簡易多行滾動

    Vue 實現(xiàn)簡易多行滾動"彈幕"效果

    這篇文章主要介紹了Vue 實現(xiàn)簡易多行滾動“彈幕”效果,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • vue實現(xiàn)移動端多格輸入框

    vue實現(xiàn)移動端多格輸入框

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)移動端多格輸入框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • VsCode新建VueJs項目的詳細(xì)步驟

    VsCode新建VueJs項目的詳細(xì)步驟

    本篇文章主要介紹了VsCode新建VueJs項目的詳細(xì)步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • 關(guān)于Vue源碼vm.$watch()內(nèi)部原理詳解

    關(guān)于Vue源碼vm.$watch()內(nèi)部原理詳解

    這篇文章主要介紹了關(guān)于Vue源碼vm.$watch()內(nèi)部原理詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • element-plus中的resetFields()方法

    element-plus中的resetFields()方法

    resetFields方法是Element Plus中el-form組件提供的一個非常有用的功能,它允許開發(fā)者輕松重置表單并移除校驗結(jié)果,本文給大家介紹element-plus中的resetFields()方法,感興趣的朋友跟隨小編一起看看吧
    2024-12-12

最新評論

黑山县| 兴和县| 新蔡县| 正镶白旗| 尼勒克县| 昌宁县| 鹤庆县| 东城区| 修水县| 武功县| 稻城县| 长寿区| 云林县| 呼和浩特市| 曲周县| 台州市| 梁平县| 南阳市| 屏山县| 泾阳县| 泰宁县| 棋牌| 阳城县| 独山县| 宿迁市| 阜新市| 马龙县| 静安区| 新津县| 丹阳市| 舒城县| 峨眉山市| 依兰县| 包头市| 宁晋县| 株洲县| 枞阳县| 淳化县| 房山区| 余江县| 宜都市|