DEV Community

Discussion on: Flask Vue.js Integration Tutorial

Collapse
 
mattiasjohnson profile image
mattiasJohnson

If I understood correctly this tutorial shows how you use flask and python when the whole index.html is a vue element. I would like to integrate flask and vue and use vue only for a few divs on my page!

I have been able to get some vue functionality by using <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> and defining some vue stuff directly in my script tags in the same html file. I would however like to be able to use Single File Components .vue files which doesn't work for my approach. I imagine I need to use vue create vueproject in my main directory but after that I'm clueless.

Do you have any ideas how to be able to implement vue with full functionality with flask and only embed the vue components in a few divs on my page?

Collapse
 
michaelbukachi profile image
Michael Bukachi • Edited

It's the same approach. Here's an example of snippets from index.html and main.js

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>web</title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but web doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app1"></div>
    <div id="app2"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

main.js:

import Vue from 'vue'
import App1 from './App1.vue'
import App2 from './App2.vue'

Vue.config.productionTip = false

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


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

Remember to build your vue files otherwise it won't work.