I have problem with register component in VueJS. I installed the component from https://github.com/wanxe/vue-button-spinner with npm install. Next I add code to my app.js (I'm using Laravel 5.5).
My app.js file
require('./bootstrap');
window.Vue = require('vue');
import Spinner from './components/Spinner.vue'
window.onload = function () {
Vue.component('button-spinner', require('./components/Spinner.vue'));
var vw = new Vue({
el: '#app',
components: {
'button-spinner': Spinner
}
});
};
And Spinner.vue code
<script>
import VueButtonSpinner from 'vue-button-spinner';
console.log('Test');
export default {
name: 'events-form',
data() {
return {
isLoading: false,
status: '',
}
},
components: {
VueButtonSpinner
},
methods: {
onSubmit() {
this.isLoading = true
$someRequest('/url', 'GET')
.then(response => {
this.isLoading = false
this.status = true // or success
setTimeout(() => { this.status = '' }, 2000) // to clear the status :)
})
.catch(error => {
console.error(error)
this.isLoading = false
this.status = false //or error
})
}
},
mounted() {
console.log('Component mounted.')
}
}
</script>
After this I run npm run dev
Next I add code to my HTML
<div id="app">
<button-spinner
:isLoading="isLoading"
:disabled="isLoading"
:status="status">
<input type="submit" :disabled="submitted" :class="{ 'disabled': submitted == true }" @click="submit('register', $event)"
v-model="registerSubmit" id="registerSubmit" style="width: 100%; height: 40px">
</button-spinner>
</div>
<script src="{{URL::asset('js/app.js')}}"></script>
And component is not working. I don't known why. Console prints Unknown custom element: <button-spinner>
EDIT:
I remove window.onload = function () from app.js after this console.log('Component mounted.') is working but from Spinner I gets [Vue warn]: Failed to mount component: template or render function not defined.found in---> <ButtonSpinner> at resources/assets/js/components/Spinner.vue<Root>
After remove window.onload there was another problem I also link additional js files in html
<script src="{{URL::asset('js/login.js')}}"></script>
<script src="{{URL::asset('js/register.js')}}"></script>
This scripts using VueJS and procudes a lot of errors.
With window.onload everything was ok. Should I include this files in app.js? Eg. register.js file https://pastebin.com/0uHxRcN9
app.js after update:
window.Vue = require('vue');
require('./bootstrap');
import Spinner from './components/Spinner.vue'
require('./register');
require('./login');
new Vue({
el: '#app',
components: {
'button-spinner': Spinner
}
});

