Software

Laravel Echo not receiving notification from pusher

Vuejs - Thu, 2017-07-27 09:24

I followed up some tutorials about echo and pusher. I configured all the project as necessary but object notifications not appear at browser. I uncoment the line

App\Providers\BroadcastServiceProvider::class,

The next files it's about what I'm using:

bootstrap.js

bootstrap.js

channels.php

Broadcast channel

PackageNotifications (class which I create the notifications) enter image description here

Line which I create a new notification

enter image description here

broadcasting.php

broadcasting.php

.env

.env

I created and registered a component in vuejs called notifications then I set it out what says in laravel notifications as you can see bellow.

enter image description here

Everything is connecting with Pusher but when I send any notification it appear at pusher but as mentioned at before, the object notification is not appearing.

view

Someone have some idea about what is happening? Thanks in advance

Categories: Software

Loading and external Javascript file in Vue.js

Vuejs - Thu, 2017-07-27 08:54

How can I include and initialize an external javascript file mymain.min.js using VueJs with webpack?

Webpack.base.conf

resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'sauJs': path.resolve(__dirname, '../src/assets/mymain.min.js'), } },
Categories: Software

Vue.js instance data missing when referencing vuex store

Vuejs - Thu, 2017-07-27 06:08

I'm attempting to use an api call to a django-rest backend to populate my data-store. The api-call appears to be working fine.

After loading index.html i can look at both store_.state.products and v.$store.state.products which both appear to have my json response from the API. You can see that here in the console after navigating to index.html: store_ object successfully is populated after the dispatch is run.

and

the v.$store reference confirms that store is populated after dispatch is run.

However, v.$data as you can see appears to be empty.

v.$data not populating

Please find below my code.

products.js

//api get call Vue.use(VueResource) function get(url, request) { return Vue.http.get(url, request) .then((response) => Promise.resolve(response)) .catch((error) => Promise.reject(error)) } //data store const apiRoot = 'http://127.0.0.1:8000/api/product-list/?format=json' const store_ = new Vuex.Store({ state: { products: [] }, mutations: { 'GET_PRODS': function (state, response) { state.products = response.body; }, 'API_FAIL': function (state, error) { console.error(error) }, }, actions: { getProducts (store) { return get(apiRoot) .then((response) => store.commit('GET_PRODS', response)) .catch((error) => store.commit('API_FAIL', error)) } } }) //products component Vue.component('product', { template: "#product-template", props: ['product'], delimiters: ["[[","]]"], }) //root instance const v = new Vue({ el: '#app', store: store_, data : function () { return { //this works fine as expected with hardcoded objects fed as data //products : [ //{ // id:1, // name:'test', // brief:'descrip', //}, //{ // id:2, // name:'other', // brief:'something else', //} //] products : this.$store.state.products }; }, delimiters: ["[[","]]"], }) //populate store.state.products with api-call v.$store.dispatch('getProducts')

index.html

<!DOCTYPE html> <html> <head> {% load static %} <link rel="stylesheet" href="{% static '/products/bootstrap.css' %}" /> <link rel="stylesheet" href="{% static '/products/bootstrap-theme.css' %}" /> <link rel="stylesheet" href="{% static '/products/base.css' %}" /> <link rel="stylesheet" href="{% static '/products/index.css' %}" /> <link rel="shortcut icon" href="{% static '/products/favicon.ico' %}" type="image/x-icon" /> </head> <body> <template id="product-template"> <div> <h1>[[ product.name ]]</h1> <h5>[[ product.brief ]]</h5> </div> </template> <div id="app"> <div class="container-fluid"> <div class="row title-row"> <h1 class="title">Products</h1> </div> <div class="row"> <product v-for="product in products" :product="product" :key="product.id"></product> </div> </div> </div> <script src="{% static "products/vue.js" %}"></script> <script src="{% static "products/vue-resource.js" %}"></script> <script src="{% static "products/vuex.js" %}"></script> <script src="{% static "products/products.js" %}"></script> </body> </html>
Categories: Software

Bootstrap-Vue card component image doesn't render

Vuejs - Thu, 2017-07-27 06:00

I am trying to get a simple Bootstrap card on a static website I am making in Vue.js. I am using Bootstrap-Vue for this. However, I cannot seem to get the image to show when I use the b-card with the img attribute. Here is the documentation on a card:

https://bootstrap-vue.js.org/docs/components/card

And here is my code that is not showing the image (all other text is rendering, even the github icon)

<b-card img="`../assets/q1.png`" title="7 Little Words" class="mb-2 col-md-6"> <!--The image above is not showing--> <h5 :style="{fontSize:1.3+'em', marginTop:20+'px'}">An addictive vocabulary puzzle for word nerds</h5> <div class="demo"> <a href="" :style="{marginBottom:10+'px'}">VIEW DEMO</a> </div> <div class="github"> <h4>Github</h4> <!--This image below is showing--> <a href=""><img src="../assets/GitHub.png" alt="GitHub"></a> </div> </b-card>

I think it must have something to do with the img attribute in the b-card, but I am not sure how to fix it. Also, here is my error in the console:

http://localhost:8080/assets/q1.png 404 (Not Found)

Categories: Software

VueJS Simple Alert Appear

Vuejs - Thu, 2017-07-27 05:42

Can someone help me make this simple alert work? What I wanted was if I click the trigger button, the text would appear but then the component should do its part.

I'm new and learning VueJS and now is in the components part but I haven't fully grasped it yet.

Here's the link: JSBIN

Snippet of the JS Script

Vue.component('alert', { template: '#alert', props: { errors:false }, data: function() { return { message:"" } }, methods: { appear: function (status) { if(status=="yes") { errors = true; message = "Appeared"; } } } }); var myapp = new Vue({ components: 'alert', el: '#app', data: { }, methods: { trigger: function() { this.$alert.appear("yes"); } } });
Categories: Software

Cannot access data from component method

Vuejs - Thu, 2017-07-27 05:37

I tried components methods in vue js. My code like this.

const Thread = Vue.component('threadpage', function(resolve) { $.get('templates/thread.html').done(function(template) { resolve({ template: template, data : function() { return { data : { title : "Data Table", count : this.GetData } }; }, methods : { GetData : function() { var data = {username : "newshubid", data : { page : 0, length : 10, schedule : "desc" } }; var args = {"data" : JSON.stringify(data)}; var params = $.param(args); var url = "http://example-url"; var result; DoXhr(url, params, function(response){ result = JSON.parse(response).data; console.log("load 1", result); }); setTimeout(function () { console.log("load 2", result); return result; }, 1000); } }, created : function(){ this.GetData(); } }); }); });

But, when I trying to use {{ data.count }} in template. Not showing result what i want. Even I tried return result in GetData.

Whats my problem ? And how to access data from methods ? Please help me, i'm a beginner. Thanks

Categories: Software

how to add permission control in laravel with vue project?

Vuejs - Thu, 2017-07-27 05:28

i'm adding vue js into my current laravel apps so i can make it SPA and thats mean laravel is only acting as backend and rest of it is controlled by vue js from rendering view to routing.

My current laravel apps using kodeine laravel-acl for controlling which page and which action that my user can do by simply

put this in route:

Route::get('admin', [ 'as' => 'admins.admin.index', 'uses' => 'UserController@index', 'middleware' => ['auth', 'acl'], 'can' => 'view.admin_view']);

and if i just do this in view to hide some action if user don't have permission

@permission('view.admin_view') //some link or button @endpermission

and all these permission is stored in mysql database and each user have different set of permission.

but how to do that if i making it vue js SPA? since all route is controlled via vue js?

Categories: Software

HOW do I right this links in my navigation bar in my vue.js project?

Vuejs - Thu, 2017-07-27 04:44

I want to right align my product and support links in my navigation bar. How do you align links in the navigation bar of a vue.js project overall?

This is how it looks now

This is the code.

<md-whiteframe class = "main-toolbar "> <md-theme name = "teal"> <md-toolbar class = ""> <router-link class = "nav-link " :to = " { name: 'levi' }" style = "color:white; text-decoration: none; ">levi</router-link> <router-link id = "nav"class = "nav-link" :to = "{ name: 'Product' }" style = "color:white; text-decoration: none;"> Product </router-link> <router-link id = "nav" class = "nav-link" :to = "{ name: 'Support' }" style = "color:white; text-decoration: none;"> Support </router-link> </md-toolbar> </md-theme> </md-whiteframe>
Categories: Software

Vue component not displayed Laravel5.4

Vuejs - Thu, 2017-07-27 03:25

I try to make broad cast notification laravel 5.4 and vuejs 2 but notification not appear any one can help me ?

navbar.blade.php

navbar


Notification.vue

Notification.vue


NotificationItem.vue

enter image description here


result npm run watch that errors appear

enter image description here


Header
enter image description here

Categories: Software

Web app with Vue.js 2 and Firebase stopped working properly

Vuejs - Thu, 2017-07-27 02:06

I had a web app hosted on my personal server. It was built with Vue.js 2 and it was working properly until last month that I checked.

Basically, it loaded some content from Firebase and after choosing some options in the app, it gave me a result.

Even if I try to display some text that is not from Firebase, it still refuses to show anything.

In the console, there are no errors, but the only message I noticed was this:

["add",{"textareas":[],"contenteditables":[],"iframes":[],"htmlghosts":[]}] bundle.js:8321:29

I'm not sure what it is. I don't know what is suddenly wrong and how to fix it.

Categories: Software

watch for a property in vue component

Vuejs - Thu, 2017-07-27 01:59

I have an async operation in parent component and need to notify child, that this operation was completed. Could I watch in child for a property change. Somewhat like:

new Vue({ props:['parentReady'], watch:{ parentReady(val){ alert('parentReady prop was changed'); } } })
Categories: Software

Execute code after view update in vue.js

Vuejs - Thu, 2017-07-27 00:44

I want to perform a task (scrolling to bottom, since new elements where added) after a view has been updated by vue.

Here is my code:

export default { mounted() { this.connect(); }, connection: null, methods: { connect: function () { ... }, onMessage: function (msg) { this.messages.push(msg); this.scrollDown(); return true; }, scrollDown: function () { $("html, body").animate({ 'scrollTop': $(this).offset().top }, 100); }

As you can see, the this.scrollDown(); is invoked after this.messages.push(msg);, so since the view is not updated immediately the scroll is not well performed. How is it supposed to be made?

Categories: Software

How to store data in VueJS with Laravel 5.4

Vuejs - Wed, 2017-07-26 23:54

Im building application like real time dashboard. Using many databases and external APIs.

(The first Idea was AJAX + Laravel Queues, but I found VueJS and It's interesting.)

The idea is to get the data in background with Laravel Queues from all sources and then storage it localy. Next step is getting this data with VueJS.

The problem I have is the storage part. I dont have idea and actually dont know how to store it so VueJS can efficiently get this data from storage and on the other hand Laravel can save the data to it the same.

There will be many users loging in a system so I created the MySQL database for them but dont know, if it's a good solution.

Thanks for advices!

Categories: Software

How to access data returned via method per item in v-for

Vuejs - Wed, 2017-07-26 21:39

I am calling a method from each item in a v-for. The method returns the proper object but I want to access that information in other pieces of my .card. Such as having the {{name}} reflect the sponsor's name returned from that method. Normally I would have the method push the data to Vue data and then access via item. But that would be strange to do for 200+ items. (Perhaps I'm missing something in that logic)

I have the following VueJS setup:

HTML:

<!--inside v-for--> <div class="card"> <p>{{ getSponsor(key) }}</p> <p>{{name}}</p> </div>

JS:

firebase () { return { deals: db.ref('deals'), businesses: db.ref('businesses') } }, methods: { getDealSponsor (key) { db.ref('businesses').child(key).on('value', snap => { return snap.val() }) } }
Categories: Software

Rendering custom nested html in Vue.js

Vuejs - Wed, 2017-07-26 20:34

I'm moving a site from AngularJS 1.x that relies heavily on the $compile service (which is no longer available in Angular 2.x. In the application I have a directive that looks something like this <myDir elemId="someRestEndPointID"></myDir> and does the following:

1) A http call is made and the response returns a string that contains a directive <myDir elemId="someRestEndPointID"></myDir>

2) A call is made to the server to for /someRestEndPointID

3) Angular gets the content and renders and looks for another <myDir> tag

4) the process is repeated (recursive)

I have not yet found something that does this for our new framework Vue.js. Is there a similar feature or library that would achieve this logic in Vue.js?

Categories: Software

VueJS and WP Rest API

Vuejs - Wed, 2017-07-26 19:53

I have a little issue here, I want to get posts (json format) from Wordpress Rest API, and I do not understand what am I missing here. Can someone helps me?

var App = new Vue({ el : '#app', data: { posts: '' }, beforeCreate: function(){ console.log('I am the first one!'); }, mounted: function(){ console.log('mounted fired'); posts = this.$resource('http://volkov.co.il/wp-json/wp/v2/posts?per_page=3'); posts.get(function(response){ this.$set('posts', response); }); }});

And here is my html:

<div id="app"> <div class="row"> <div class="large-12 columns"> <article class="post-article" v-for="post in posts"> <h1>post title</h1> <h3>{{ post.id }}</h3> </article> </div> </div> </div> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.3.4/vue-resource.js"></script> <script src="js/app.js" charset="utf-8"></script>

As you can see I am using vue-resource library. I am running this code from local machine. What am I missing here? Thanks

Categories: Software

Vue2 - Using :checked on checkbox input, breaks default behaviour

Vuejs - Wed, 2017-07-26 19:17

I'm doing a "status update" component of sorts, in my actual component I'm marking the first custom checkbox (the circles at top, etc.) as checked...but for the CodePen below, I just marked them all as :checked='false' to iterate my issue.

The "twitter" checkboxes won't check and uncheck. The Facebook ones will.

I'm certain this has to do with the fact that I'm enabling/disabling a character counter on the twitter checkboxes. If you click one of the twitter checkboxes, you'll notice the character counter turn on, but the checkbox is never checked...

For example, in the method toggleMaxCharLength(), if I comment out self.enableMaxCharLength = true;, the checkbox work as they should.

If I remove the :checked='false' from the input v-for, works as it should...

https://codepen.io/mikebarwick/pen/qXdqBO

Categories: Software

How to access the router from winthin a component

Vuejs - Wed, 2017-07-26 19:09

I'd like to show a modal when /url/confirm/ is requested.

This is what've done so far:

// footer component import Modal from '../Modal/Modal'; export default { components: {Modal,}, data() { return { showModal: false, }; }, mounted() { if (window.location.href.match('/confirm/')) { this.showModal = true; } }, }; // my main js import MyFooter from './components/footer/MyFooter; import router from './router'; new Vue({ el: '#app', router, components: {MyFooter, /* other components too */} });

And I combined with this https://router.vuejs.org/en/essentials/dynamic-matching.html#reacting-to-params-changes to cover all use cases?

This works but does not seem to be a vue way to do things, especially that I do the same thing in two different files.

How do I detect a /confirm/ route whose name is confirm in vue in order to display the modal from within my component footer?

Categories: Software

Add class on click in vuejs

Vuejs - Wed, 2017-07-26 18:41

this my vue template

<div class="col-sm-4 col-xs-6 thumb" v-for="(photo, index) in photos" @click.prevent="check(index)"> <a class="thumbnail" :class="{'active': photo.checked}"> <img class="img-responsive" :src="photo.picture" alt=""> </a> </div>

and this is check() method:

check(index) { if(!("checked" in this.photos[index])) this.photos[index].checked = true else this.photos[index].checked = !this.photos[index].checked },

every thing seem good for me but it's not working what the problem could be???

Categories: Software

Error when trying to display value using v-for in vue

Vuejs - Wed, 2017-07-26 18:30

I have some trouble with understanding an error I am receiving using vue.js and hope that someone can help me out here. I believe that it is a silly mistake but I am unable to spot it.

I am receiving this error here: Use of undefined constant providers - assumed 'providers'. I am using laravel and blade here. I receive this error in the browser. I assume that it has something to do with the way I am trying to display the providers object using v-for loop in vue.js and since I am a beginner, I am probably making a mistake here. Here is my code:

Component:

Vue.component('filter-section', { template: "#filter-template", props: ['providers'] }); // create a root instance new Vue({ el: '#home-filter-result' });

Filter-blade.php

<div id="home-filter-result"> <filter-section v-for="item in providers" :providers='{!! $providers !!}'> </filter-section> <template id="filter-template"> {{ item }} </template> </div>

Providers is an object in this format:

providers : Array[20] 0:Object

value1: '1'

value2: '2'

value3: '3'

Categories: Software

Pages