在Vue.js中使用compute并在挂载时调用了calculated属性仍然为空

时间:2018-12-05 13:44:12

标签: vue.js vuejs2 vue-component

我是Vue.js的新手。我正在开发一个组件,该组件可以在客户轮到时(在他们前面没有更多的客户)通过视频聊天自动连接客户和销售代表。我需要通过调用函数startMyVisit()来激活第三方视频聊天软件。

以前,我通常在函数Error: visit argument is not of type MyCustomerVisit的第一行中遇到错误startMyVisit()。我在调试器的那一行上停了下来,this.getVisit的值是''。我创建了一个按钮来手动调用startMyVisit(),它可以正常工作。因此,我的结论是,我致电startMyVisit()的时机错误或不正确。

我通过在 computing 属性watcher上使用getVisit并在startMyVisit()时调用方法getVisit来解决此错误不是null或为空。

computing 属性getVisit不为null或为空并且调用方法startMyVisit()时,我得到一个错误[Vue warn]: Error in callback for watcher "getVisit": "ReferenceError: startMyVisit is not defined"和{ {1}}。

我已验证该方法的书写和拼写正确(使用 copy paste 进行验证)。

我将不胜感激。

这是我的 waitingDetails.vue 组件的代码(最新):

vue.runtime.esm.js?2b0e:1737 ReferenceError: startMyVisit is not defined

2 个答案:

答案 0 :(得分:0)

您尝试过nextTick()吗?这样。

mounted(){
    this.$nextTick(() => {
        this.startMyVisit()
    })
},

这应该使您的组件有机会正确完成加载并在下一个刻度上调用startMyVisit方法。

答案 1 :(得分:0)

我认为您的输入错误可能会引起问题。在您的观察者中,您具有以下代码:

Private Sub Command299_Click()
Const strParent = "C:\Users\xxx\xxx\Jobs\"
Dim strJobID As String
Dim strClient As String
Dim strFolder As String
Dim fso As Object
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Get year from control - modify as needed
strClient = "(" & Me.[Client ID] & ") " & [Client Name]
' Path with year
strFolder = strParent & strClient
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
    ' If not, create it
    fso.CreateFolder strFolder
End If
' Get student ID from control
strJobID = Me.[Job ID] & " " & [Job name]
' Full path
strFolder = strFolder & "\" & strJobID
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
    ' If not, create it
    fso.CreateFolder strFolder
End If
' Open it
Shell "explorer.exe " & strFolder, vbNormalFocus
End Sub

但是我认为您需要将if (this.getVisit !== null && this.getVisit !== '') { console.log('watch: getVisit !== null and is not empty!'); startMyVisit(); } else { console.log('watch: getVisit is NULL or is EMPTY'); } 更改为startMyVisit();