[Vuejs]-Running a Vue app from within a Golang/Gin template

0👍

Was able to get it working by using vue-loader and webpack, compiling my app to a single index.js file, with an entry point that looks like this:

import Vue from 'vue'
import App from './App.vue'

new Vue({
  render: h => h(App),
}).$mount('#webapp')

then invoking in a template like this:

<div id="webapp">Failed to load Vue</div>

<script src=/webapp/dist/index.js></script>

It only works if the script tag is AFTER the div, or Vue wont be able to find the element.
I also had to add the following in main.go so that it could read the JS

r.Static("/webapp", "./webapp")

All in all, ended up being a fairly simple solution, the minutiae of config just held me up!
I’m sure I’ll run into some type of issue taking this to production, but that is tomorrow’s problem

Leave a comment