Answer the question
In order to leave comments, you need to log in
How to embed vue.js into an existing project?
Everywhere they write that vue.js can be implemented gradually on a working site. But somehow I couldn't find anywhere how to do it correctly. Any manual or step by step on vue.js begins with the words "Let's create the first vuejs application." But I don't need an app. I need, for example, to make a form and arrange it as a component in order to place it on several pages.
So far, I'm doing this:
1) connected vue.js
2) screwed up Vue.component()
3) profit??? Of course not.
I want to split my component into several. They may have a voluminous pattern. In short, I come to the conclusion that you need to do a "single-file component". Somehow to collect them with webpack, etc. And then again "create a vuejs application"...
How to be in such a situation? What to read? How to do it step by step?
Answer the question
In order to leave comments, you need to log in
If you need to use Vue for individual modules (widgets, forms, etc.), then do it like this:
import Vue from 'vue';
import VueComponent from './VueComponent.vue';
const element = document.getElementById('element');
new Vue({
el: element,
template: `<vue-component/>`,
components: {
VueComponent,
},
});
Your vision of your "problem".
1. Connect the Vue distribution on the page via CDN or locally.
2. Transfer the piece of page code that needs to be brought under the control of Vue into a separate js file.
3. Instead of this piece of code on the page, place an element with an identifier (id) - when rendering, your Vue component will fit here as a result.
4. Modify the transferred code in the js file under Vue - create a Vue component.
5. Include js-file on the page.
6. Profit.
PS
This way you can make Vue components - as many as you like.
In the end, you still have to redo everything completely. This is exactly what I came up with, because the approaches are too different - building a SPA project and trying to gradually implement.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question