J
J
JohnDaniels2018-11-23 06:17:08
Vue.js
JohnDaniels, 2018-11-23 06:17:08

How to properly embed vue.js in a "regular" site?

Hello.
There is a site on laravel, where on one of the pages it was necessary to make several interactive blocks using vue (slider, questionnaire, dragdrop, something else).
now I just connected vue and the necessary libraries on this page

<script src="{{ url('js/libs/vue.min.js') }}"></script>
<script src="{{ url('js/libs/vue-awesome-swiper.js') }}"></script>
<script src="{{ url('js/libs/vue-radial-progress.min.js') }}"></script>

итд

and wrote one script, something like this:
Vue.use(VueAwesomeSwiper)
Vue.use(RadialProgressBar)

new Vue({
    el: '#slider_view',
    //логика
})

new Vue({
    el: '#dragdrop_view',
    //логика
})

new Vue({
    el: '#test_view',
    //логика
})

everything works, but how correct is this (in particular, separate vue instances for each element)?
Vue is already "full" used in the admin, with webpack and all, is it possible to use it somehow?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Larin, 2018-11-23
@fanrok

Correct in my opinion. I don't see anything wrong with multiple vue instances. This is my favorite part of vue - the ability to embed it anywhere without breaking other functionality.

A
atawerrus, 2018-11-23
@atawerrus

In fact, it was possible to wrap in a div with id app, put a View instance on the element, and then create methods that would respond to events, v-on: click, etc.

A
aden, 2018-11-23
@aden

in such cases, I make loadable components that are loaded only if they are used on the page and connect them in one instance of the view

S
semki096, 2018-11-24
@semki096

It seems to me that vue is already in Laravel, if so, then the docs should be written how to work correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question