Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VueJS with a Go backend

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.

like image 691
Gilbert Nwaiwu Avatar asked Aug 03 '16 13:08

Gilbert Nwaiwu


People also ask

What backend should I use with Vue?

WordPress. If you are looking for a no-code Vue JS backend, then you should consider WordPress. Mainly if you are working on small Vue JS web applications, then the use of WordPress is the right decision.

Can VueJS be used for backend?

VueJS is agnostic about the backend. Any backend that that can send/receive data in JSON format is fine for VueJS. So the best backend is the one that you are familiar with and meet your needs.

Is VueJS front end or backend?

The result was Vue. js, which is one of the most popular frontend frameworks in use today.


2 Answers

If 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

like image 52
gurghet Avatar answered Sep 24 '22 07:09

gurghet


At the Go's side you can define your own delimiters: https://golang.org/pkg/text/template/#Template.Delims

like image 26
RdB Avatar answered Sep 23 '22 07:09

RdB