I've been playing with Vue on jsfiddle for a while, so thought I would drop an example app into a new Laravel project and try the Gulp/Vueify pipeline.
I'm getting errors and I am a bit too new to understand where I am going wrong. Would really appreciate some pointers.
app.js
var bus = new Vue();
Vue.component('cart', require('./components/Cart.vue'));
const app = new Vue({
el: '.container',
data: function() {
return {
quantity: 0
};
},
created: function() {
// store this to use with Vue.set
var temp = this;
// on number event set data
bus.$on('event-qty-changed', function (qtyNew) {
// vm.$set deprecated
Vue.set(temp, 'quantity', qtyNew);
})
},
computed:{
gold: function(){
return this.quantity * 200;
}
}
});
Cart.vue
<template>
<div>
<h2>How many gems would you like to buy?</h2>
<p>1 emerald costs 100 pieces of gold.</p>
<input type="number" v-model="quantity" class="form-control">
</div>
</template>
<script>
export default {
data () {
return {
quantity : 0
}
},
watch: {
'quantity': function (qtyNew, qtyOld) {
console.log('quantity changed from %s to %s', qtyOld, qtyNew);
bus.$emit('event-qty-changed', qtyNew);
}
}
}
</script>
index.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<link rel="stylesheet" href="{{ elixir('css/app.css') }}">
</head>
<body id="app">
<div class="container">
<h1>Gem Market</h1>
<hr>
<cart></cart>
<hr>
<h3>You have to pay <strong>@{{ gold }}</strong> pieces of gold.</h3>
<div>
<script src="/js/app.js"></script>
</body>
</html>
Errors:
vue.js?3de6:2611[Vue warn]: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as .
[Vue warn]: Error in watcher "quantity"
(found in component at /home/vagrant/vueplay/resources/assets/js/components/Cart.vue)
Uncaught (in promise) ReferenceError: bus is not defined(…)