Closed beatscode closed 7 years ago
Still trying to understand but components seemed to render when I set the option.Data as a function. Seems like o.SetDataWithMethods and o.Data were clashing overwrote the data object.
func InitMainComponent() {
m := &MainComponent{
Object: js.Global.Get("Object").New(),
}
o := vue.NewOption()
o.SetDataWithMethods(m)
o.Data = func() interface{} {
data := make(map[string]interface{})
data["currentRoute"] = "/"
return data
}
fmt.Println("Data", o.Data)
o.AddMethod("ChangeRoute", func(vm *vue.ViewModel, args []*js.Object) {
currentRoute := args[0]
vm.Data.Set("currentRoute", currentRoute)
})
fmt.Println("Data", o.Data)
// o.SetRender(func(vm *vue.ViewModel, fn vue.CreateElement) {
// })
o.Template = MainTemplate
o.NewComponent().Register("main-layout")
}
I'm not able to use CurrentRoute property in the view. I get
ReferenceError: Can't find variable: currentRoute
in the console onload. When running vue.NewComponent... I can gain access to the data property in the view. But I need to implement a render method for the component so I needed to use the NewOption api.Is there something I'm doing wrong?