1. 程式人生 > 程式設計 >javascript物件3個屬性特徵

javascript物件3個屬性特徵

1.父元件和子元件的傳值,函式的傳遞式觸發

子元件:

 1 <template>
 2     <div class="show-operation">
 3         
 4             <input type="text" v-model='info.name'>
 5             <input type="text" v-model='info.id'>
 6             <input type="text" v-model='info.ctime'>
 7             <input type="button" value="修改" @click="modify">
 8
<button><router-link to=/classes>cancel</router-link></button> 9 10 <!-- 設定函式@click=觸發函式 --> 11 </div> 12 </template> 13 14 <script> 15 export default { 16 name: 'modify', 17 data(){ 18 return{ 19 info:"",
20 change:false 21 } 22 }, 23 mounted(){ 24 this.info = this.$route.query.per_info 25 26 }, 27 28 29 methods:{ 30 modify(){ 31 console.log("子元件") 32 this.$emit("modify", [this.info, this.$route.query.per_info.id])
33 34 } 35 } 36 37 } 38 </script> 39 40 <style> 41 .show-operation{ 42 position: absolute; 43 top: 200px; 44 left: 200px; 45 background-color: red; 46 width:200px; 47 height: 200px; 48 z-index: 5; 49 } 50 </style>

父元件:

1  <transition mode="out-in">
2      <router-view @modify="modify"></router-view>                                      
3  </transition>
4    
script
{
  modify(){
  console.log('123')
}
}

2. router-link的傳值方式

<router-link :to="{path:'/classes/modify', query:{per_info:item}}">修改資訊</router-link> 使用 :to的動態繫結,可以指定query附加引數 3渲染資料後,修改頁面資料不重新整理的問題 使用強制重新整理或者修改資料的地址和長度(記憶體發生變化) 或者用:key繫結唯一識別符號 4.元件傳遞 動態繫結的引數 傳遞動態的繫結的引數,引數改變後,父元件接收的引數也會改變,並且無需再用函式觸發