I'm trying to do a simple js method with Vue 3 but in the console appears Uncaught TypeError: Vue is not a constructor.
This vue project is installed inside a laravel project, hence the structure. I tried exactly the same with the same code in Vue 2 and it's working.
After many tests I know the main problem is that piece of code in the form.js with the new Vue({}) syntax.
I searched but there's no any answer for this syntax in particulary.
Any idea how I should write it in Vue 3?
form.js
new Vue({
el: '#form',
methods: {
clickme: function () {
alert('Hello World');
console.log('Its working');
},
},
});
app.js
import './bootstrap';
import Alpine from 'alpinejs';
window.Alpine = Alpine;
Alpine.start();
window.Vue = require('vue').default;
if ($('#form').length > 0) {
require('./form.js');
} else {
const app = new Vue({
el: '#app',
});
}
form.blade.php
<div id="form">
<button @click="clickme()">Click me</button>
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>