国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue props 單向數據流的實現

2024-05-06 15:28:12
字體:
來源:轉載
供稿:網友

1、props通信

注意:DOM模板的駝峰命名props要轉為短橫分割命名。

<!DOCTYPE html><html lang="zh">  <head>    <meta charset="UTF-8" />    <title>Vue</title>  </head>  <body>    <div id="app">      <my-component message='來自父組件的數據' warning-text="提示信息"></my-component>    </div>    <script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>    <script type="text/javascript">      Vue.component('my-component', {        template: '<div>{{warningText}}:{{message}}</div>',        props: ['message', 'warningText']      })      new Vue({        el: "#app"      })    </script>  </body></html>

傳遞動態數據(v-bind):

<!DOCTYPE html><html lang="zh">  <head>    <meta charset="UTF-8" />    <title>Vue</title>  </head>  <body>    <div id="app">      <input type="text" v-model="parentMessage" />      <my-component :message='parentMessage'></my-component>    </div>    <script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>    <script type="text/javascript">      Vue.component('my-component', {        template: '<div>{{message}}</div>',        props: ['message']      })      new Vue({        el: "#app",        data: {          parentMessage: ''        }//前端全棧開發交流群:      })//866109638    </script>//幫助1-3年工作人員  </body>//突破技術瓶頸,提升思維能力</html>

2、單向數據流

(1)子組件保存父組件傳遞過來的值,在子組件自己的作用域下修改和使用。

<!DOCTYPE html><html lang="zh">  <head>    <meta charset="UTF-8" />    <title>Vue</title>  </head>  <body>    <div id="app">      <my-component :init-count='1'></my-component>    </div>    <script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>    <script type="text/javascript">      Vue.component('my-component', {        template: '<div>{{initCount}}</div>',        props: ['initCount'],        data: function() {          return this.initCount        }      })      new Vue({        el: "#app"      })    </script>  </body></html>

(2)使用計算屬性

<!DOCTYPE html><html lang="zh">  <head>    <meta charset="UTF-8" />    <title>Vue</title>  </head>//前端全棧交流學習圈://866109386,幫助1-3年前端人員  <body>//突破技術瓶頸,提升思維能力    <div id="app">      <my-component :width='100'></my-component>    </div>    <script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>    <script type="text/javascript">      Vue.component('my-component', {        template: '<div :style="style">組件內容</div>',        props: ['width'],        computed: {          style: function() {            return {              width: this.width + 'px'            }          }        }      })      new Vue({        el: "#app"      })    </script>  </body></html>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 济宁市| 连江县| 栖霞市| 阜南县| 内江市| 东乡县| 甘谷县| 房产| 宁化县| 牙克石市| 云阳县| 于都县| 顺昌县| 龙岩市| 溆浦县| 东海县| 邯郸市| 绥化市| 赞皇县| 昌吉市| 龙南县| 旺苍县| 精河县| 阿合奇县| 囊谦县| 阿巴嘎旗| 肥乡县| 类乌齐县| 札达县| 郴州市| 许昌市| 明光市| 抚顺市| 莎车县| 隆安县| 连南| 积石山| 应用必备| 延川县| 富蕴县| 阜康市|