I want to use Go templates as well as VueJS for data-binding. Has anyone integrated both before?
I wish to use VueJS primarily for Ajax calls as doing it manually(or with jQuery) always leaves my code messy.
To be more specific, if I have a simple<p>
tag whose value is generated from a Go template like so:
{{.Color}}
Now I want to bind to the value in
like so:
{{someVariable}}
Both are for the same tag.
I want to use Go templates as well as VueJS for data-binding. Has anyone integrated both before?
I wish to use VueJS primarily for Ajax calls as doing it manually(or with jQuery) always leaves my code messy.
To be more specific, if I have a simple<p>
tag whose value is generated from a Go template like so:
{{.Color}}
Now I want to bind to the value in
like so:
{{someVariable}}
Both are for the same tag.
Share Improve this question edited Feb 22, 2018 at 15:03 Michael W. Czechowski 3,4572 gold badges25 silver badges52 bronze badges asked Aug 3, 2016 at 13:16 Gilbert NwaiwuGilbert Nwaiwu 7282 gold badges15 silver badges41 bronze badges 2- 2 Please make your question more specific – gurghet Commented Aug 3, 2016 at 13:25
- Edited the original question – Gilbert Nwaiwu Commented Aug 3, 2016 at 14:38
2 Answers
Reset to default 14If you are mixing Vue.js with another templating system you can choose to change the interpolating delimiters (by default['{{','}}']
) with something else.
Vue.config.delimiters = ['${', '}']
Now you can use {{.}}
with golang and ${}
with Vue
At the Go's side you can define your own delimiters: https://golang/pkg/text/template/#Template.Delims