Software

passing user input to another component in vue.js

Vuejs - Mon, 2017-08-28 20:40

I'm fairly new to vue.js but I couldn't seem to find a concrete answer for what I'm looking for but I also am new enough that I might have been looking right at the answer and not known it. So.

What I'm trying to do is create a 1 page application that tracks turns basically. It will:

  1. takes user input on how many users are participating
  2. ask for the names of all the users
  3. use the names which I currently have saved in an array, to build user cards, just showing the name of each user.
  4. You will click your name when your turn is over and the next persons card/button will 'raise' and then they click it, etc.

I'm currently having a hard time with that 3rd part. I need to figure out how I can pass this array of users to my other component's data object so I can use vue.js to loop and just spit the cards out.

initial-start.vue - template

<template lang="html"> <div> <div> <h1>How many users?</h1> <input type="number" id="myNumber" value="0"> <button v-on:click="getUsers">Submit</button> <app-area v-if="users > 0 && users < 5"></app-area> </div> </div> </template>

initial-start.vue - script

<script> export default { methods:{ getUsers(){ var counter = 0; var users = []; var x = document.getElementById("myNumber").value; if (x <= 0){ alert('Please choose a number greater than 0.'); }else if(x > 4){ alert('Maximum 4 users!'); }else{ alert('thank you for that.') } while(counter < x){ name = prompt('Please enter your names.'); users.push(name); counter++; } return users; } } } </script>

app-area.vue - template

<template lang="html"> <div> <h1>Turn: {{ turn }}</h1> <userCards></userCards> </div> </template>

app-area.vue - script

<script> export default { data() { return{ turn: 0, users: [] } }, props: ['users'] } </script>

The question is, "How do I get the array from the getUsers() function, into the app area where I would be able to loop like

<userCards v-for="user in users"></userCards>

and have a card/button for each person entered ?"

Categories: Software

vue with axios - unwanted redirect

Vuejs - Mon, 2017-08-28 19:51

I'm trying to login user. When I send correct data

Vue.axios.post(context.state.userAuthLinks.login, { email: playload.email, password: playload.password })

it works fine, but when I try to post wrong data, vue app reload with

http://localhost:8080/?email=asd%40gmail.com&password=asdasdasd#/

also, I found stange thing. When I, for example, sing up new user with the same email, to get error, app does not reload... It happens not only with dev server. On product server the same error.

full method

loginUser(context, playload) { return new Promise((loginResolve, loginReject) => { Vue.axios.post(context.state.userAuthLinks.login, { email: playload.email, password: playload.password }).then(function(res) { loginResolve(res); context.commit('setUserId', res.data.userId); context.commit('setUserToken', res.data.id); context.commit('setUserAuthenticated', true); }).catch(function(error) { // here it don't stops with 'debugger' console.log(error); loginReject(error); }); }); },

Also, I have theese headers

Vue.axios.defaults.baseURL = 'http://localhost:3000'; Vue.axios.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
Categories: Software

How to deal with empty response in axios?

Vuejs - Mon, 2017-08-28 19:21

I use axios with vue.js to fetch data as unlimited pagination. It works fine expect when there is no data to render:

fetchData() { this.loading = true this.page++; axios.get(this.BASE_URL + '/api/jokes/'+'?page='+this.page).then( response => this.jokes = response.data).catch(function (error) { console.log(error); });

I'm wondering how to stop rendering when we reached to the last page and there is no more data to display?

I've looked at the docs but could not find my answer.

Categories: Software

vuejs component not rendering in my laravel 5.3 blade page

Vuejs - Mon, 2017-08-28 18:55

I am using laravel 5.3 and vue 1.0.26 version and it is unable to load components into blade pages. It showing empty. I was just trying with given laravel example component.

If any body have solution please suggest.

my app-laravel.js file

require('./bootstrap'); Vue.component('example', require('./components/Example.vue')); const app = new Vue({ el: 'body' });

my blade page looks like

<div class="col-10 text-muted"> <example></example> </div>

and am using gulp which looks like

elixir(mix => { mix.sass('app.scss', 'public/css/app.min.css') .scripts([ '../../../node_modules/jquery/dist/jquery.min.js', 'libraries/datatables.responsive.js', 'libraries/datatables.responsive.bootstrap4.js', '../../../node_modules/vue/dist/vue.min.js', 'app.js', ], 'public/js/app.min.js'); });
Categories: Software

Get matrix data from a dynamic table

Vuejs - Mon, 2017-08-28 18:14

i am building a dynamic table, passing the columns and rows from an input, i need to build the data that is edited inside it with contenteditable atribute.

So after i pass number rows and columns i can edit the cells inside the html table, after that i have a create input, and i need to somehow get the data inside like a matrix for example

like this: dataTable[0][0] = "John"

at the moment i can't get any data :/

I tried to associate a v-model to the current index, like this:

Here i pass my number of rows and columns:

<div class="col-md-2"> <input type="number" min="1" v-model="table.rows" class="form-control" id="rows"> </div> <label for="columns" class="control-label col-md-1">columns:</label> <div class="col-md-2"> <input type="number" min="1" v-model="table.cols" class="form-control" id="cols"> </div>

here i iterate over the number of rows and columns to create the editable

<table class="table table-responsive" style="background-color:lightGray"> <tbody> <tr v-for="(row,idx2) in tableRows"> <td v-model="table.colsArr[idx]" class="table-success" v-for="(col,idx) in tableCols" contenteditable="true">{{idx}}</td> </tr> </tbody> </table>

Finally i have the data structure where i try to create that matrix, i tried with a simple array without success:

d

ata() { return { table: { rows: 1, cols: 1, key: "Table", tableStyle: 1, colsArr:[] }, insert: 1, }

when i create the table i want to show the elements, nothing is inside at the moment :/

alert("HEY:",this.table.colsArr[0]);
Categories: Software

How to scroll to top of page automatically in vue.js

Vuejs - Mon, 2017-08-28 17:56

I'm trying to implement unlimited scrolling with vue.js and MugenScroll

The code is like this:

<template> <div class="jokes" v-for="joke in jokes"> <strong>{{joke.body}}</strong> <small>{{joke.upvotes}}</small> <div> <mugen-scroll :handler="fetchData" :should-handle="!loading"> loading... </mugen-scroll> <template> ... data () { return { jokes:[], comments: [], id: '', loading: false, page: 0, url: '' } }, methods: { fetchData() { this.loading = true; this.page++; axios.get(this.BASE_URL + '/api/jokes/'+'?page='+this.page).then( response => this.jokes = response.data); //how to scroll to the top of the newly fetched data ? this.loading = false },

The infinite scrolling works but the issue is that after the first page being fetched, the browser then scrolls immediately to the second page, as the DOM remained at the bottom. So I need to move the scroll to the top to avoid new page being rendered by a slight move down. How can I acheive this?

Categories: Software

Node.js + Vue.js: why is console.log() in vue.js files not showing in console?

Vuejs - Mon, 2017-08-28 16:39

I'm new to javascript development and I have a real project here. Let me describe:

  1. There is a project, an Express (Node.js) server that has a /public/app folder
  2. There is another project, a Vue.js app that has a /dist folder
  3. In the Express /public/app folder is copypasted vue.js application (copied from another project from /dist folder)
  4. Vue.js app runs at http://localhost:3000/app/#/

I've added some console.log() commands into a different files/places in a vue.js app code, for example:

app.ts

... import {store} from './store/store'; import {isBoolean} from 'util'; console.log('APP'); let router = new VueRouter({ routes: [ { path: '/', component: WelcomeComponent }, ...

or in component:

... import * as common from '../../../store/common'; import * as country from '../../../store/country'; console.log('COMPONENT'); @Component({ template: require('./template.html'), components: { 'layout': LayoutContent2, ...

and so on. But none of the console.log() messages are displayed in a browser console. Im sure that an app is builded and copied correctly. So why can't I see the messages in console?

Categories: Software

CSS style sheet not working after uploading the file on server with filezilla

Vuejs - Mon, 2017-08-28 16:13

My project is done in laravel and vue.js, i have a separate css style sheets and all styles sheets are gulped into a common css style sheet. and it renders on production. Just after the production only some styles are working and most of the styles are not working, I use fileZilla to upload.

and all ccustomizations and configurations perfectly done. I guess something goes wrong in npm production. in local machine all styles are perfectly working.

I found a similar question on stack overflow but nothing worked.

Categories: Software

two way binding not working with table rows and cols

Vuejs - Mon, 2017-08-28 15:58

I have 2 inputs, called col and row which i can change and they are related to the columns and rows of a table.

I want to see that table and edit his content, at the moment i have a v-model that updates my data with the row and columns, and need to put that in my v-for for the table so the table should get automaticly updated.

The problem is that the table is not getting updated.

This is what i have:

<div class="col-md-2"> <input type="number" min="1" v-model="table.rows" class="form-control" id="rows"> </div> <label for="columns" class="control-label col-md-1">columns:</label> <div class="col-md-2"> <input type="number" min="1" v-model="table.cols" class="form-control" id="cols"> </div> <table class="table"> <tbody v-for="row in table.rows"> <tr> <td contenteditable="true">John</td> </tr> </tbody> </table> data() { return { table: { rows: 1, cols: 1, key: "Table", tableStyle: 1, }, insert: 1, } }

,

Any help?

Categories: Software

vue-multiselect sort selected

Vuejs - Mon, 2017-08-28 15:39

Is there any way to have the selected items using vue-mulitiselect in vuejs and Laravel5.4 sorted by value. For example if I choose “node2” first than choose “node1” I want it to auto order/sort them like “node1 node2”.

Thanks

Categories: Software

Webstorm with vue project - dev server not restarting

Vuejs - Mon, 2017-08-28 15:26

The first few times I make changes the dev server restarts rapidly. After that, there's a good chance it won't restart the first time I save a change.. I often have to insert code that will not compile at all to get it to recompile, then revert that change. It also starts taking longer and longer. It will say "5000ms" but in actuality it might take 20 seconds.

There's got to be something buggy about how webstorm works with a vue cli project's dev server.

Categories: Software

Is it possible to run VueJS dev server without port?

Vuejs - Mon, 2017-08-28 13:55

When I write npm run dev it starts on http://localhost:8080

Is it possible run on http://testdomain.local/? (without port)

Categories: Software

vue.js form submit did not get the new value of model-bind

Vuejs - Mon, 2017-08-28 13:46

I have a form

HTML:

<form ref="myForm" action="/AAA/BBB" method="get"> <input type="text" hidden="hidden" v-model="myValue" name="myName" /> </form> <button v-on:click="Send">Click me</button>

JS

new Vue({ data: { myValue: 1 }, methods: { Send: function() { this.myValue = 2; this.$refs.myForm.submit(); } } })

When i click the button, it will send the value: 1

I'm sure that the value was modified before form submit

Categories: Software

Vue.js + Firebase - How to display deeply nested Database

Vuejs - Mon, 2017-08-28 13:20

this is my first question here because this is making me crazy. I am fiddling around with firebase and vue.js trying to loop thru my database(key-value) construct.

Below is my exported json:

{ "city" : { "new york" : { "zipcode" : { "10039" : { "street" : { " W 152nd St" : [ "263", "250", "21" ] } }, "02116" : { "street : { " W 155nd St" : [ "3", "25", "21" ] } } } }, "boston" : { "zipcode" : { "02116" : { "street : { "Berkeley St" : [ "161", "65", "13" ] } } } } } }

What else should I tell you? I thought this structure would help me generating a quad-devided depented dropdown like [city [v]] [zipcode [v]] [street [v]] [number [v]].

Thanks in advance for your time and help.

Categories: Software

Data-binding with <slot> in Vue.js

Vuejs - Mon, 2017-08-28 13:15

I created a login panel in Vue.js using Bootstrap CSS framework. Also, InputGroup component, because of help on back-end side. The purpose is not to write id="user_id" in Login.vue component, but in InputGroup.vue. It must be dynamic, in this case it does not write manually "user_id", but only takes data from the "field" props. The second problem is how to change the class, when is error on logging, add input class to tag "form-control-danger", but do not add class in "Login.vue" component, but in "InputGroup.vue" component. Thanks for help.

Login.vue

<form class="form-group has-error" @submit.prevent="checkUser"> <input-group field="user_id"> <label class="text-muted" for="user_id">User ID</label> <input class="form-control" type="number" id="user_id" v-model="form.userId" min="1" required> </input-group> <button class="btn btn-info btn-local">login</button> </form> <script> import InputGroup from './input-group/InputGroup.vue' import Form from './Form.js' // Form.js this is a class javascript file which helps in validation e.g. user ID. export default { name: 'LoginLocal', components: { 'input-group': InputGroup }, data() { return { form: new Form({ userId: '' }), }; }, methods: { checkUser() { this.form.post('/api/somewhere/users/' + this.form.userId + '/login') .then(() => this.$router.push('/')) .catch(error => window.handleError(error)) .catch(response => { if (response.status === 404) { return this.form.errors.recordCustom('user_id', 'Invalid User ID'); } }); }, }, }; </script>

InputGroup.vue

<template> <div class="form-group" :class="{ 'has-danger': parent.form.errors.has(field) }"> <slot></slot> <div class="form-control-feedback">{{ $parent.form.errors.get(field) }}</div> </div> </template> <script> export default { props: ['field'], }; </script>
Categories: Software

nightwatch fails when initializing page object

Vuejs - Mon, 2017-08-28 13:06

I'm trying to test a Vue application. I have 2 simple page objects, and 2 simple spec files. When i run the e2e test, the first one (login) passes with no problem but the second one fails with this error:

Error: No selector property for element "client" Instead found properties: capabilities,globals,sessionId,options,launchUrl,launch_url,screenshotsPath,Keys,session,sessions,timeouts,timeoutsAsyncScript,timeoutsImplicitWait,elemen t,elementIdElement,elements,elementIdElements,elementActive,elementIdAttribute,elementIdClick,elementIdCssProperty,elementIdDisplayed,elementIdLocationInView,elementIdLocation,elementIdName,elementIdClear,elementIdSelected,elemen tIdEnabled,elementIdEquals,elementIdSize,elementIdText,elementIdValue,submit,source,contexts,currentContext,setContext,getOrientation,setOrientation,moveTo,doubleClick,mouseButtonClick,mouseButtonDown,mouseButtonUp,execute,execut eAsync,execute_async,frame,frameParent,window,windowHandle,windowMaximize,window_handle,windowHandles,window_handles,windowSize,windowPosition,refresh,back,forward,screenshot,url,status,title,keys,cookie,acceptAlert,accept_alert, dismissAlert,setAlertText,getAlertText,dismiss_alert,sessionLog,sessionLogTypes,click,clearValue,getAttribute,getCssProperty,getElementSize,getLocation,getLocationInView,getTagName,getText,getValue,isVisible,moveToElement,setValu e,submitForm,sendKeys,switchWindow,resizeWindow,setWindowPosition,maximizeWindow,saveScreenshot,getTitle,closeWindow,init,urlHash,getCookies,getCookie,setCookie,deleteCookie,deleteCookies,injectScript,getLogTypes,getLog,isLogAvai lable,waitForElementNotPresent,waitForElementNotVisible,waitForElementPresent,waitForElementVisible,end,pause,perform,useCss,useRecursion,useXpath,page,expect,assert,verify,currentTest,parent,name at new Element (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\element.js:11:11) at C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:39:35 at Array.forEach (native) at C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:35:24 at Array.forEach (native) at module.exports.createElements (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:34:14) at Object.Page (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page.js:19:6) at Object.parent.(anonymous function) [as tenant] (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\core\api.js:469:16) at Object.before (C:/aquaprojects/src/bitbucket.org/scalock/tenantmanager/client/test/e2e/specs/tenants.spec.js:7:26) at Object. (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\util\utils.js:35:8)

login.js:

module.exports = { url: 'http://localhost:8080/#/login', elements: { app: '#app', loginSection: '.login-page', title: 'h3', submitButton: '.btn-primary', username: '#username', password: '#password' } }

login.spec.js:

let login = null module.exports = { before: function (client) { console.log('*********** Init login page *******************') login = client.page.login() }, 'open login page': function () { login .navigate() .waitForElementVisible('@app', 5000) .assert.elementPresent('@loginSection') .assert.containsText('@title', 'Tenant Manager Login') }, 'try to login': function () { login.setValue('@username', 'administrator') login.setValue('@password', '1234') login.click('@submitButton') login.waitForElementNotPresent('@submitButton') }, after: function (client) { client.end() } }

This one passes, the other one, which is basically copy/paste, with a few changes, fails on this line:

tenant = client.page.tenant()

tenant.js:

module.exports = { url: 'http://localhost:8080/#/tenants', elements: { tab: '#tenants', tenantsFilter: '.tenants-filter input', statusFilter: '.status-filter input', add: '.add-tenant' } }

tenants.spec.js:

let tenant = null module.exports = { before: function (client) { console.log('*********** Init tenant page *******************') tenant = client.page.tenant() }, 'open tenant page': function () { console.log('*********** Navigating to tenant page *******************') tenant .navigate() .waitForElementVisible('@tab', 5000) .assert.elementPresent('@tenantsFilter') // .assert.containsText('@title', 'Tenant Manager Login') }, after: function (client) { client.end() } }
Categories: Software

IS there a way to edit External Vue.js plugins from inside the component file that imports it?

Vuejs - Mon, 2017-08-28 12:46

For example, I'm using vue-charts.js and imported it into my root component:

import VueChartjs from 'vue-chartjs'; Vue.component('bar-chart', { extends: VueChartjs.HorizontalBar, ... })

Now VueChartjs is a wrapper for Charts.js so the component comes with its own template. I'd like to be able to edit that template within VueChartjs.HorizontalBar or the component bar-chartthat I mounted it onto.

Is there anyway to do this within this root component?

Categories: Software

jQuery plugins not initialised in vuejs when loading a page using vue-router, Is it possible

Vuejs - Mon, 2017-08-28 12:38

I have a collection of jQuery plugins in the file jquery-plugin-collection.js and I initialise the plugins in the file custom.js. When I reload the page, all the plugins are being initialised. but when I load the page using vue-router, the plugins are not initialised. I made alot of google research with no result. Am wondering if am the first to face this issue.

Categories: Software

v-show and v-if don't work on Laravel blade

Vuejs - Mon, 2017-08-28 12:22

This is not a duplicated question because I cannot find on SO a situation as simple as mine.

I'm manually trying to recreate an accordion

My html:

@foreach($device_menu_data['top_brands'] as $top_brand) <div class="brand_name" v-on:click="setVisibleBrand('{{$top_brand->brand}}')" > {{ $top_brand->brand }} <i class="fa fa-arrow-down device-list-toggler"></i></span> </div> <div class="brand_devices" v-if="visibleBrand === '{{$top_brand->brand}}'"> ....content of the duv </div> @endforeach

My js:

const open_device_menu_app = new Vue({ el: '#layout_header_container', data: { visibleBrand: 'none', }, methods: { setVisibleBrand: function(brand_name) { this.visibleBrand = brand_name; console.log(this.visibleBrand); } } });

When I click on brand name, the console logs the right name. I was expecting that the specific brand_device will be shown after a click on the brand_name. But this doesn't happen. Both using v-if and v-show do not change.

Why?

Categories: Software

How to make timeline in Vue.js?

Vuejs - Mon, 2017-08-28 11:23

Does anyone know good libraries for timelines? I tried vis.js, but couldn't figure out how to include it to my vue component. (btw, I'm using webpack)

Categories: Software

Pages