Vue.js 我需要使用挂载还是创建?

Vue.js 我需要使用挂载还是创建?,vue.js,vuetify.js,Vue.js,Vuetify.js,我正在使用VUE。我必须将一个ID从父组件传递到子组件,但是当我在挂载上这样做时,它只在第一次呈现页面时起作用,然后通过我编程的按钮再次调用子组件,ID为null。我是否需要调用created()或其他方法?我应该如何对该方法进行编码(创建) 我的代码 <template> <childComponent :empid="employeeID"> </childComponent> </template> <script>

我正在使用VUE。我必须将一个ID从父组件传递到子组件,但是当我在挂载上这样做时,它只在第一次呈现页面时起作用,然后通过我编程的按钮再次调用子组件,ID为null。我是否需要调用created()或其他方法?我应该如何对该方法进行编码(创建)

我的代码

<template> 
  <childComponent :empid="employeeID"> </childComponent> 
</template>

<script>
 ...
 data () {
  return {
    employeeID: null,
 },
 mounted () {
  this.getID()
 },
 methods: {
  getID () {
    this.employeeID = this.params.entity.employee
    // console.log(this.employeeID) // returns null on second time that I called the page
 }
</script>

...
数据(){
返回{
employeeID:null,
},
挂载(){
这是getID()
},
方法:{
getID(){
this.employeeID=this.params.entity.employee
//console.log(this.employeeID)//在我第二次调用页面时返回null
}

改用计算属性:

<childComponent :empid="employeeID"> </childComponent> 

请改用计算属性:

<childComponent :empid="employeeID"> </childComponent> 

this.params.entity.employee
引用的是什么?您的意思是使用路由参数吗?因为这样就可以了。创建的$route.params.employee可能对服务器端效果有用(调用API).使用
watcher
computed
属性。若要将路由参数与ID绑定。@Dirk V,this.params.entity.employee正在从另一个父组件引用,我将其用作child=props:['params']中的道具.this.params.entity.employee引用的是什么?您的意思是使用路由参数吗?因为这样就可以了。创建的$route.params.employee可能对服务器端效果有用(调用API)。使用
watcher
computed
属性。要将路由参数与ID绑定。@Dirk V,this.params.entity.employee是从另一个父组件引用的,我将其用作child=props:['params'].@A.Lau,
fer.trecool
是一个新的贡献者,我认为他无法将答案标记为“已解决”但是,他可以吗?@A.Lau,
fer.trecool
是一个新的贡献者,我认为他还不能将答案标记为“已解决”,是吗?