Software

Switcher of languages on Vue.js

Vuejs - Tue, 2017-09-05 13:06

Good day :)

Got to study Vue.js 2nd version, everything is still going according to plan, but there are some nuances and I would like to hear a pro

Now we turn to the essence of the problem

On the site there is a language switch, it works all by standards, in the template comes arrays of languages:

$headerBar = [ 'langs' => [ [ 'name' => 'Українська', 'img' => 'images/flags/ua.png', 'code' => 'ua', 'active' => true, ], [ 'name' => 'Русский', 'img' => 'images/flags/ru.png', 'code' => 'ru', 'active' => false, ], [ 'name' => 'English', 'img' => 'images/flags/uk.png', 'code' => 'uk', 'active' => false, ] ] ];

Language output template:

<template slot="language-bar"> <language-switcher v-bind:langs='{!! json_encode($langs) !!}'></language-switcher> </template>

And the component vue.js itself:

<template> <div class="lang-currency-switcher-wrap" :class="{ show: isVisible }"> <div class="lang-currency-switcher dropdown-toggle" @click="isVisible = true"> <span class="language"> <img :alt="activeLang.name" :src="activeLang.img"></span> <span class="currency">{{ activeLang.code }}</span> </div> <div class="dropdown-menu"> <a v-for="lang in langs" v-if="!lang.active" class="dropdown-item"> <img :src="lang.img" alt="">{{ lang.name }} </a> </div> </div> </div> </template> <script> export default { props: ['langs'], data() { return { isVisible: false }; }, computed: { activeLang() { let activeLang = []; for (let lang of this.langs) { if (lang.active) { activeLang = lang; } } return activeLang; } }, mounted() { } } </script>

It works like this: The server renders an array of languages ​​with clever calculations, one of which is active, it all comes to the blade template and the vue.js component is already called

The component vue.js in its turn outputs an available list of languages ​​except active, and the active calculates and displays for the user.

When the user clicks on the language wrapper, then vue displays the entire available list.

Now the question is:

How correctly to hide all languages, in that cases, if the user clicked on any of the areas of the site, except the most wrapper languages?

Also interesting is the criticism, perhaps it could have been done differently, in a more beautiful way :)

Thank you.

Categories: Software

What is best way indicate best value in table Vue

Vuejs - Tue, 2017-09-05 12:48

Hello i have table in Vue template and in table have speed's and time's values. And i want indicate the higher speed and lower time value. And i can have several equal values.

I call method set do something calculation (its just example, sorry for this horror) with array and object bestOf and in template show with conditional directive.

Q:How correctly i can show this best values in tables with Vue API (directives, computed values) or maybe not need use Vue API (i did so)?

Code:

var table = new Vue({ el: '#app-4', template: ` <div v-if="visible" id="sumTable"> <table id="dataTable"> <tbody> <tr v-for="(competitor,index) in competitors"> <td>{{competitor.start}}<span style="color:red" v-if="bestOf.start[index]">&#9733</span></td> <td>{{competitor.speed}}<span style="color:red" v-if="bestOf.speed[index]">&#9733</span></td> </tr> </tbody> </table></div>`, data: { visible: false, competitors: [{ start: '', speed: '', }], bestOf: { start: {}, speed: {}, } }, created: function () { window.addEventListener('keyup', this.tableVisible) }, methods: { tableVisible: function (event) { if (event.keyCode === 88) { this.visible = !this.visible; if (this.visible) { window.calculateRaceStatsTable() } } }, set: function (newArray) { newArray.data.forEach(function(competitor,index,array){ if (!this.bestOf['start'].value || this.bestOf['start'].value > parseFloat(competitor['start'])){ this.bestOf['start'] = {}; Vue.set(this.bestOf['start'],'value',parseFloat(competitor['start'])) Vue.set(this.bestOf['start'],index,true) } else if (this.bestOf['start'].value === parseFloat(competitor['start'])) { Vue.set(this.bestOf['start'],index,true) } if (!this.bestOf['speed'].value || this.bestOf['speed'].value < parseFloat(competitor['speed'])){ this.bestOf['speed'] = {}; Vue.set(this.bestOf['speed'],'value',parseFloat(competitor['speed'])) Vue.set(this.bestOf['speed'],index,true) } else if (this.bestOf['speed'].value === parseFloat(competitor['speed'])) { Vue.set(this.bestOf['speed'],index,true) } }.bind(this)) this.competitors = newArray.data.slice() } } })
Categories: Software

Not able to update the data with onchange in vue js 2

Vuejs - Tue, 2017-09-05 12:39

I am not able to update the updated data to the child component when doing on-change from a select box with local data/object. But I am able to load data to the child component everytime when I click the submit button with the help of API. I need help to refresh my child component with my updated data when I do the on-change from the select box. Find the below code which I'm trying.

Component-1:

<template> <div> <div class="row"> <select v-model="selectedemp" @change="filterempdata($event.target.value)"> <option value="">Select emp/option> <option v-for="option in empfilterlist" v-bind:value="option.value" v-bind:key="option.value">{{ option.text }}</option> </select> </div> <div class="compone"> <empView v-if='loading' :empDetails='empData'></empView> </div> <div class="col-lg-6 col-md-6"> <button type="button" id="btn2" class="btn btn-danger btn-md" v-on:click="getEmpDetails">Fetch Data</button> </div> </div> </template> <script> import updatedemp from './empView' export default { name: 'cluster', components: { 'empView': updatedemp }, data () { return { loading: false, emptData: null, empfilterlist: [ { text: 'Department', value: '1' }, { text: 'Status', value: '2' }, ], selectedemp: '', } }, methods: { filterempdata: function (selectedoption) { console.log(') this.empData.WorkflowFilter = selectedoption this.empData = this.empData }, getEmpDetails: function () { this.$http.get('http://localhost:7070/getemmdata') .then((response) => { this.empData = response.data this.loading = true }, response => { console.log('test' + JSON.stringify(response)) } ) } } } </script>

Component: 2

<template> <div class="empView"> <div class="col-lg-6 col-md-6"> <h3>{{ empid }}</h3> </div> <div class="col-lg-6 col-md-6"> {{ empname }} </div> </div> </template> <script> export default { name: 'empView', props: ['empDetails'], data () { return { empid: this.empDetails.id, empname: this.empDetails.name } }, watch: { workflowDetails: function (changes) { this.empid = changes.id this.empname = changes.name } } } </script>
Categories: Software

v-for inside table in Vuejs

Vuejs - Tue, 2017-09-05 12:06

Hello everyone I'm having a table which has following set:

Table image

I'm having years dynamic which needs to be displayed through v-for loop, In general we can have codes like this:

<table class="table table-striped"> <tbody> <tr> <th class="text-center">Brokerage</th> <th class="text-center">Analyst Name</th> <th class="text-center">Report Date</th> <th class="text-center" colspan="2">Target Price</th> <th class="text-center">Change in TP</th> <th class="text-center">Reco</th> <th class="text-center" colspan="3">Sales</th> <th class="text-center" colspan="3">EBITDA</th> <th class="text-center" colspan="3">PAT</th> <th class="text-center">Document Link</th> </tr> <tr> <th class="blue_bg"></th> <th class="blue_bg"></th> <th class="blue_bg"></th> <th class="blue_bg">Old</th> <th class="blue_bg">Revised</th> <th class="blue_bg"></th> <th class="blue_bg"></th> <th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th> <th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th> <th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th> <th class="blue_bg"></th> </tr> </tbody> </table>

Since my years are dynamic I want to have v-for loop for

<th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th> <th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th> <th class="blue_bg">Year 1</th> <th class="blue_bg">Year 2</th> <th class="blue_bg">Year 3</th>

Also for displaying data set I'm already having v-for loop, so it will be v-for loop inside v-for loop

<tr v-for="(item, index) in tableFilter"> //dsiplaying data set </tr>

Help me out in this, thanks.

Categories: Software

Can't put a div above my draggable section without affecting the behaviour

Vuejs - Tue, 2017-09-05 11:34

I am working with vuejs draggable sortable, and basicly i have 2 lists, list1 and list2, i want to drag items from list1 to list2.

At the beginning i need to have a div above my list2, or something similiar can be just a paragraph to indicate that the user should drag the elements there. if i try to put the div inside the draggable it affects the behaviour of the same, if i center the paragraph for example and try to drag elements above that paragraph in the div it don't consider it as a draggable zone, any help with this?

this is my draggable list2:

<draggable class="box" @change="elementPosition" v-model="myList" :options="{group: getSectionOptions,put:false }"> <transition-group id="list2" class="box-header with-border drop-zone style-scroll" style="overflow-y: auto; height:80vh;display:block;padding:5px" name="list-complete"> <div v-for="(value, key, index) in myList" :key="key" @click.prevent="changeView(value.key,key)" v-if="value.key != 'Document'" class="panel panel-color list-complete-item item"> <div class="quote box-body"> <p v-if="value.key"> <span class="spanWidth" v-if="value.key == 'line break' || value.key == 'page break'">Break</span> <span class="spanWidth" v-else>{{value.key}}</span> <span class="spanWidth text-muted" v-if="value.key == 'Table'"> (rows:{{value.rows}};cols:{{value.cols}})</span> <span class="spanWidth text-muted" v-if="value.key == 'Paragraph'">({{ value.text | truncate }})</span> <span class="spanWidth text-muted" v-if="value.key == 'Image'"> (width:{{value.width}};height:{{value.height}})</span> <span class="spanWidth text-muted" v-if="value.key == 'heading'"> ({{value.headingType}})</span> <span class="spanWidth text-muted" v-if="value.key == 'line break' || value.key == 'page break'">({{value.key}})</span> <span class="spanWidth text-muted" v-if="value.key == 'List'">(items:{{value.items.length}})</span> <span @click.stop="removeSection(index,key)" class="pull-right spanWidth"><i class="fa fa-lg fa-close"></i></span> </p> <p v-if="!value.key">{{value.description}}</p> </div> </div> </transition-group> </draggable>
Categories: Software

How does one get an active instance of socket.io?

Vuejs - Tue, 2017-09-05 11:04
io.on('connection', socket => { })

This snippet gives you instance 'socket', but I am currently in need of using that instance somewhere else in my project.

Is there a way of accessing it by the port it's running on or similar?

I am trying to change the state in Vuex (Vue.js) with Sockets, which I'd put into a handler in a REST Api.

Categories: Software

Vue carousel - setting icons as navigation labels

Vuejs - Tue, 2017-09-05 11:02

I am using this vue carousel package, and I am trying to set the icons as navigation buttons, like this:

<carousel :perPage="1" :navigationEnabled="true" :navigationNextLabel="'<i class="material-icons">keyboard_arrow_right</i>'" :navigationPrevLabel="'<i class="material-icons">keyboard_arrow_left</i>'" > <slide v-for="testimonial of testimonials" :key="testimonial.id"> <img v-if="testimonial.image" :src="testimonial.image.data.path" class="is-96x96"> <h4>{{ testimonial.title }}</h4> <p>{{ testimonial.excerpt }}</p> </slide> </carousel>

But, for some reason, it is not working, I get this as the output in the html:

enter image description here

Categories: Software

Html, Vue, Laravel - loop in v-for and table

Vuejs - Tue, 2017-09-05 10:49

I hava a simple table, every tr is a link with a sepcific order, but I have to have one extra column n th with checking or this order is already in store. ( with checboxes ) I can't to this because when I add this, then all row i a link, but I want to this last column wasn't a link, but simple checboxes. Here is my code:

<table class="table"> <tr> <th>Order Number</th> <th>Name</th> <th>Tel</th> <th>Email</th> <th>Status</th> <th>Order date</th> <th>IS in store?</th> </tr> <router-link :to="'/orderDetail/'+order.id" tag="tr" v-for="order in orders" :key="order.number" class="order-row"> <td>{{order.number}}</td> <td>{{order.client_name}}</td> <td>{{order.phone}}</td> <td>{{order.email}}</td> <td>{{order.actual_status}}</td> <td>{{order.order_date}}</td> <td>Here should be checbox with id of roder, but not as a link</td> </router-link> </table>
Categories: Software

Error in callback for watcher, Vue JS

Vuejs - Tue, 2017-09-05 10:46

I am using this mixin - But it gives me an error in IE11, not in Chrome, FF, Safari, so it seems it's only a IE related issue..

The error im getting is: Error in callback for watcher "inViewport.now": "TypeError: Object doesn't support this action" (WAT?)

The watcher code looks like:

watch: { 'inViewport.now': function(visible) { if(visible) { this.loadDataToSystem(); this.elementIsVisible = true; //Update graph with new data this.resetTimer(); this.updateGraphOptions.minutes = updateIn; this.updateGraphDataTimer = setInterval(function () { this.loadDataToSystem(); }.bind(this), 300000); } else { this.elementIsVisible = false; //Stop updating graph this.stopTimer(); clearInterval(this.updateGraphDataTimer); this.updateGraphOptions.minutes = null; this.updateGraphOptions.started = false; } } },

Do anyone have an idea on what is wrong?

Categories: Software

Vuejs $emit didn't trigger parent's function on callback

Vuejs - Tue, 2017-09-05 10:45

My question is just like this one:Vuejs $emit doesn't fire on callback. But I used the superagent in my project. Here is my code:

//Parent.vue <Child v-on:savevideo="toSaveVideo"/> ... methods:{ toSaveVideo:function(data){ console.log('add'); } } //Child.vue <button @click="toAdd">Add</button> ... methods:{ toAdd:function(){ ... let self = this; superagent .get(url) .query({data:data}) .end(function(err,res){ //trigger parent function let resData = res.body.data; self.$emit('savevideo',resData); }) } }

The request is successful but when trigger 'savevideo', the method 'toSaveVideo' in parent didn't print anything. However, when I put the emit outside the callback, everything is fine. Why does the $emit event not fire in a callback?

Categories: Software

Vue: Show image from Storage as Background

Vuejs - Tue, 2017-09-05 09:59

Actually I have this code, where I access to assets folder(inside of public).

<div class="itemProjectImage" :id="'itemProjectImage_'+i" :style="'background-image:url(/assets/img/projects/'+project.slug+'/home.jpg'"> </div>

What I really want is access like this to storage, but with vue.

<p class="lead"><img src="{{ asset('/storage/employees/'.$employee->slug.'/'.$employee->slug.'.'.'jpg') }}" width="50%" ></p>

¿Which is the correct way?

Thanks

Categories: Software

Making a transition on div in vue.js

Vuejs - Tue, 2017-09-05 09:52

I want to fade my div when I click one of my A. I can not do it. Can you help me? Here's my code

<div class="item"> <transition name="fade"> <div v-if="show"> <a @click.prevent="Submit(0); show = !show;" href="#"></a> <a @click.prevent="Submit(1); show = !show;" href="#"></a> </div> </transition> </div> data() { return { show: true, }
Categories: Software

Component method response object data binding

Vuejs - Tue, 2017-09-05 09:49

I am starting to lose my mind in debugging an application that I inherited from a fellow developer who is absent. I have narrowed down the problem to the following place in code (php files are checked, Vue instances are initialised, there are no syntax errors).

This is my the component that gets initialised:

var RadniStol = Vue.component('radnistol', { template: '#template-RadniStol', data() { return { tableData: [], requestData: { sort: "ID", order: "DESC" } } }, methods: { reloadTable: function (event) { data = this.requestData; this.$http.post('php/get/radni_stol.php', data).then(response => { console.log(response.data.bodyText); this.tableData = response.data.records; }); }, . . .

The PHP file that gets called with the POST method is working correctly, querying the database and echoing the response in a JSON format.

The thing that is making me pull out my hair is the following: the console.log(response.data) outputs the following into the console:

{"records":[{"DODAN_NA_RADNI_STOL":"1","..."}]}

It is an JSON object that I expected to have but when trying to assign it to the data of the component with:

this.tableData = response.data;

or any other way… response.data.records returns ‘undefined’ in the console. I have tryed with JSON.parse() but no success.

When logging types to console: response variable is a response object with a status 200 and body and bodyText containing the data from the database. response.data is a string type containing the string JSON with the data from the database.

I am really starting to lose my mind over this issue, please help!

Thank you

Categories: Software

Watch for data change

Vuejs - Tue, 2017-09-05 09:36

I'm currently struggling with the Vue instance concept. I'm using the vue-loader with webpack and created a vue component that I'm importing.

import Vue from 'vue'; import Search from '../Search.vue'; const vm = new Vue({ el: 'search', render: h => h(search) });

On the component:

export default { data: function() { return { results: 'current results' } } }

I want trigger and event from inside of the component (on a property change) that I can watch from the instance.

Using the API should be something like this:

vm.$watch('results', function (newVal, oldVal) { // do something })

But I does not trigger anything.

I think I'm missing to understand how to use the Vue instance because I can't also add any data on initialization of the instance that is accessible on the component like:

const vm = new Vue({ el: 'search', data: {index: 1}, render: h => h(search) });

Index is also not available inside of the component to use.

How do I fix this?

Categories: Software

Failed to mount component using vue-js-toggle-button

Vuejs - Tue, 2017-09-05 09:20

I tried to use the plugin for a project with Vue 2 but got a Vue warn like below.

[Vue warn]: Failed to mount component: template or render function not defined

Inside vue component:

import ToggleButton from 'vue-js-toggle-button' export default { components: { ToggleButton } }

Then,

<toggle-button :value="true" :labels="{checked: 'Foo', unchecked: 'Bar'}"/>

The plugin is not that popular and any help would be much appreciated.

Categories: Software

Laravel 5.5 bootstrap error

Vuejs - Tue, 2017-09-05 07:35

I am getting below error.

Uncaught Error: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript.

app.js

require('./bootstrap'); window.Vue = require('vue'); import Vue from 'vue'; import VueRouter from 'vue-router'; Vue.use(VueRouter); import VueAxios from 'vue-axios'; import axios from 'axios'; Vue.use(VueAxios, axios); import App from './App.vue'; import Login from './components/Login.vue'; import Register from './components/Register.vue'; import Activity from './components/Activity.vue'; import SelectPersons from './components/SelectPersons.vue'; const routes = [ { name: 'Login', path: '/', component: Login }, { name: 'Register', path: '/register', component: Register }, { name: 'Activity', path: '/activity', component: Activity }, { name: 'SelectPersons', path: '/selectpersons', component: SelectPersons } ]; const router = new VueRouter({ mode: 'history', routes: routes}); new Vue(Vue.util.extend({ router }, App)).$mount('#app');

bootstrap.js

window._ = require('lodash'); /** * We'll load jQuery and the Bootstrap jQuery plugin which provides support * for JavaScript based Bootstrap features such as modals and tabs. This * code may be modified to fit the specific needs of your application. */ try { window.$ = window.jQuery = require('jquery'); require('bootstrap-sass'); } catch (e) {} window.Vue = require('vue'); /** * We'll load the axios HTTP library which allows us to easily issue requests * to our Laravel back-end. This library automatically handles sending the * CSRF token as a header based on the value of the "XSRF" token cookie. */ window.axios = require('axios'); window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /** * Next we will register the CSRF Token as a common header with Axios so that * all outgoing HTTP requests automatically have it attached. This is just * a simple convenience so we don't have to attach every token manually. */ let token = document.head.querySelector('meta[name="csrf-token"]'); if (token) { window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; } else { console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); } /** * Echo exposes an expressive API for subscribing to channels and listening * for events that are broadcast by Laravel. Echo and event broadcasting * allows your team to easily build robust real-time web applications. */ // import Echo from 'laravel-echo' // window.Pusher = require('pusher-js'); // window.Echo = new Echo({ // broadcaster: 'pusher', // key: 'your-pusher-key' // });

Here is the file that loads every vue component or blade template pages.

<html> <head> {{Html::style('/css/bootstrap.css')}} {{Html::style('/css/style.css')}} {{Html::script('/js/bootstrap.js')}} </head> <body> <div id="app"> </div> <script src="{{asset('js/app.js')}}"></script> </body> </html>

I am using Laravel with vue. Can anybody help me to solve this issue?

Thanks

Categories: Software

Vue JS v-attr=“expression1 && exp2 && exp3” are not working

Vuejs - Tue, 2017-09-05 07:24

Vue JS v-attr=“expression1 && exp2 && exp3” are not working. I am also tried ${&}${&} and like #{&}#{&} and &amp;&amp; and also like

#{&amp;}#{&amp;}

Code is available in JSFiddle

http://jsfiddle.net/yMv7y/3330/
Categories: Software

What framework to chose for the UI in an Enterprise Web Application?

Vuejs - Tue, 2017-09-05 06:43

I am working on an enterprise web application which is to be developed from scratch but traditionally the team has been using JSF for the UI with JE7 for the backend.

While JE7 is a great idea for the backend enterprise web app it is the front end that bothers me.

I am evaluating as to what could be a better framework for the front end instead of JSF? Maybe React or Vue or Angular or good old friend jQuery backed up by require.js for Asynchronous Module Definiton (AMD) of Javascript?

I read a number of posts as these :https://dzone.com/articles/vuejs-is-good-but-is-it-better-than-angular-or-rea and https://medium.com/reverdev/why-we-moved-from-angular-2-to-vue-js-and-why-we-didnt-choose-react-ef807d9f4163

If anyone has had the opportunity of a similar decision making before please share your learning.

P.S. I am aware that SO is not the right platform to post such a question but I could get the most meaningful insights on my thoughts only here.

Categories: Software

Moving Logic from Directive to Method in Vue Compoment

Vuejs - Tue, 2017-09-05 04:21

I have a VueJS component that targets the style attr like this:

<section :style="{ backgroundImage: src && 'url(' + src + ')' }"> ... <script> export default { props: ['src'] } </script>

Now, this works exactly as I wish it to (it includes the style attr if the user enters a image url and does not include it if he/she does not.

However, my understanding is that it is 'better' (in general) to separate my logic out into a method rather than include it within the :style directive.

Now, I am fairly new to VueJS and do not have a strong JavaScript backgrand and am trying to figure out how to do that, but have not been able.

As such, I'm wondering if someone could show me how to write a method (or some other recommend best practice) to achieve the same result.

Thanks.

Categories: Software

Vue.js: Cannot find module './check-versions'

Vuejs - Tue, 2017-09-05 00:42

I'm developing a Vue.js app based on the webpack template generated by vue init webpack <name-of-project>.

Everything had been working just fine, but now when I try npm run dev or npm run build I get the error:

Error: Cannot find module './check-versions' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (C:\Users\Bertie\bertie-wheen-online\build\build.js:1:63) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)

I first tried generating a fresh project with vue init webpack test-webpack and compared a few key files (package.json, build/dev-server.js, build/build.js, build/webpack.base.conf.js) with the ones in my project to make sure nothing major had changed (except for my installing vue-resource and a couple of loaders for Sass and Slm, which had been working fine before). I also checked that the failing commands worked for test-webpack (to make sure it wasn't something with my system that had inexplicably gone wrong), which they did.

I then tried deleting my node_modules/ directory and re-npm install-ing, which didn't help.

Hopefully I'm missing something obvious, but I'm at a bit of a loss to figure out how to progress from here (unless I generate a fresh project and move everything across, but that feels unsatisfactorily like side-stepping the problem). What should I do? (If you need to look at any of my files to diagnose the problem, ask for them in a comment and I'll upload them.)

Categories: Software

Pages