1

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?

9
  • You will need to have a Vue app on the index page itself, and then you simply include your contact form as a component–if it is written as a component, that is. Commented Apr 8, 2019 at 21:43
  • 1
    ive no idea what vue is, however you normally include the html (or a template of some sort) in the executing application and not include the application in the html, I hope that makes sense. Commented Apr 8, 2019 at 21:44
  • 1
    @Chris - if you're using a front end framework, like Vue, the framework needs to know the template, meaning you're probably going to use an API, which also means the executing application typically won't contain any HTML, just JSON. Commented Apr 8, 2019 at 21:46
  • @Terry, your approach would mean that I would need to transform the existing html page to a vue project first? That's actually what I couldn't handle so far... Commented Apr 8, 2019 at 21:47
  • 2
    You don't. You simply include the script for VueJS, initialise an empty #app container and plug your contact form in there. You can still leave all of index.html intact. Commented Apr 8, 2019 at 21:48

1 Answer 1

3

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.