我在尝试实现接口(在golang的其他程序包中定义)时遇到了一些问题。我对下面的问题做了些微的阐述
接口:
package interfaces
type Interface interface {
do(param int) int
}
Run Code Online (Sandbox Code Playgroud)
实现方式:
package implementations
type Implementation struct{}
func (implementation *Implementation) do(param int) int {
return param
}
Run Code Online (Sandbox Code Playgroud)
Main.go:
package main
import (
"test/implementing-interface-in-different-package/implementations"
"test/implementing-interface-in-different-package/interfaces"
)
func main() {
var interfaceImpl interfaces.Interface
interfaceImpl = &implementations.Implementation{}
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
test/implementing-interface-in-different-package
./main.go:10:16: cannot use implementations.Implementation literal (type
implementations.Implementation) as type interfaces.Interface in assignment:
implementations.Implementation does not implement interfaces.Interface (missing interfaces.do method)
have implementations.do(int) int
want interfaces.do(int) int
Run Code Online (Sandbox Code Playgroud)
是否可以从其他包中实现接口?
谢谢!
更新:此错误仅在启用 vuex 严格模式时发生
我正在使用 Firebase 身份验证构建 Vue 应用程序,但该应用程序失败并显示以下错误消息:
[Vue 警告]:观察者回调错误“function () { return this._data.$$state }”:“错误:[vuex] 不要在变异处理程序之外改变 vuex 存储状态。”
错误:[vuex] 不要在变异处理程序之外改变 vuex 存储状态。
未捕获的 RangeError:超出最大调用堆栈大小
当我将用户提交到我的 main.ts 文件中的 Vuex 存储时发生错误:
firebase.auth().onAuthStateChanged(user => {
if (user) {
store.commit(constants.auth.SET_USER, user) // THIS LINE
store.commit(constants.auth.SET_AUTHENTICATED, true)
router.push('/')
} else {
store.commit(constants.auth.SET_USER, null)
store.commit(constants.auth.SET_AUTHENTICATED, false)
router.push('/signup')
}
if (!app) {
app = new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app')
}
})
Run Code Online (Sandbox Code Playgroud)
这是我的突变:
[constants.auth.SET_USER](state: AuthState, payload: firebase.User): void {
state.user = payload
}
Run Code Online (Sandbox Code Playgroud)
我可以从 …