Integrate existing static html website into existing vue js web app

不问归期 提交于 2020-04-18 07:12:09

问题


I created a contact form with vue and vuetify as a new vue project. Now I would like to integrate it into the existing static html page. I tried to add the vue app as a vue instance which didn't seem to be the right approach. Would it be easier to existing html & css code into the new light weight vue project setup?

Can you recommend a simple github project as an example which includes vue just as an instance into an existing website?


回答1:


Vue's can be praised for many reasons but one of the most outstanding ones would be its scalability. You can use Vue simply for rendering a button or to create large scale applications.

All you need is to load vue.js and target the app element, using its id. Vue doesn't care what's outside that element (but can access the rest of the page, if required). You can even have multiple Vue instances on the same page.

Example:

<div id="contactForm">
  <div v-text="limits" :style="appStyle"></div>
</div>
<p>You can have any html outside your vue app, it will display... normally. 
</p>
<p>You can place your vue instance anywhere you want, as long as the element you instantiate it on exists in DOM when you try to instantiate it.
<p>And <code>vue.js</code> has to be loaded before you call the constructor. That's about it.</p>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
  new Vue({
    el: '#contactForm',
    computed: {
      limits(){ return 'There are no limits.' },
      appStyle() { return {
          color: 'red',
          border: '1px solid #ddd'
        }
      } 
    }
  });
</script>


来源:https://stackoverflow.com/questions/55582158/integrate-existing-static-html-website-into-existing-vue-js-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!