1. 程式人生 > >vue 父元件傳值給子元件 子元件的銷燬與重置 外部呼叫自己的函式

vue 父元件傳值給子元件 子元件的銷燬與重置 外部呼叫自己的函式

 <rolesadd @my-event="addRoles = false" :IsOfficial="IsOfficial"></rolesadd>
// 父元件  :IsOfficial  子元件接收值   IsOfficial  要傳的值

    props: {
      IsOfficial: Boolean,
    },
<el-checkbox  v-if="IsOfficial==true">是否開放</el-checkbox>
// 子元件 在props裡放要取的值 後面是型別   就可以直接使用了

普通型別:字串(String)、數字(Number)、布林值(Boolean)、空(Null)

引用型別:陣列(Array)、物件(Object)

借鑑的部落格

<companychange @my-event="changeCompany = false" :IsOfficial="IsOfficial" v-if="hackReset" ></companychange>
// 加個if判斷

//  在事件中先false 在true就行了
 hackReset(that); 
window.hackReset=function(that){    //  元件銷燬重置功能
    that.hackReset = false;//銷燬元件
    that.$nextTick(() => {
      that.hackReset = true
    })
}
function ajaxGet2 (that, myUrl, data, callback){
  that.$http.get(url + myUrl, { params: data, headers: headers }).then(response => {          //用於讀取型別與請求方式
    if (typeof (response) != "undefined") {
      callback(response);
      console.log(headers);
    }
  });
}
export { //很關鍵
    ajaxGet2
}

//    釋放
import {ajaxGet2} from '@/js/my.js'
//    引入