Vuejs

Subscribe to Vuejs feed
most recent 30 from stackoverflow.com 2017-09-14T21:10:11Z
Updated: 7 years 1 week ago

vue js router + firebase authentication

Sun, 2017-08-27 02:08

I use vue js 2.4.2 , vue router 2.7.0 , and firebase 4.3.0. I can't get the route authentication stuff to work. This is my current route.js

import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) import Firebase from './firebase' import Dashboard from './components/Dashboard.vue' import Auth from './components/Auth.vue' let router = new Router({ mode: 'history', routes: [ { path: '/', component: Dashboard, meta: { auth: true } }, { path: '/login', component: Auth } ] }) router.beforeEach((to, from, next) => { if (to.matched.some(record => record.meta.auth)) { if (!Firebase.auth().currentUser) { next({ path: '/login' }) } else { next() } } else { next() } }) export default router

But now everytime I go to / it redirects me back to /login, probably because the Firebase.auth().currentUser is null, even though I am in fact logged in. How do I fix this?

Categories: Software

How do i count new lines with vuejs from textarea?

Sun, 2017-08-27 01:10

I try to count new lines from textarea with vuejs i have this textarea

<textarea v-model="modelarea" v-on:keyup="show"> </textarea>

vuejs code

new Vue({ data:{ modelarea:'' }, methods: { show: function(){ var length = 0; for(var i = 0; i < this.modelarea.length; ++i){ if(this.modelarea[i] == '\n') { length++; } } } })

and echo it

<label>{{ length }}</label>

But it don't work the function I think is wrong.

Categories: Software

Vue Wizard Form radio button validation

Sun, 2017-08-27 00:18

I am working with vue-form-wizard by Cristi Jora integrating Element UI the basic example is here

Vue.use(VueFormWizard) new Vue({ el: '#app', data: { formInline: { user: '', region: '', gender: '' }, rules: { user: [{ required: true, message: 'Please input Activity name', trigger: 'blur' }, { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' }], region: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }], } }, methods: { onComplete: function() { alert('Yay. Done!'); }, validateFirstStep() { return new Promise((resolve, reject) => { this.$refs.ruleForm.validate((valid) => { resolve(valid); }); }) } } })

https://jsfiddle.net/bt5dhqtf/409

but i am not able to validate radio buttons, please help me :(

here is my example https://jsfiddle.net/bt5dhqtf/884/

Categories: Software

Nuxt build throwing WebpackOptionsValidationError on Heroku

Sun, 2017-08-27 00:18

I am trying to put a NuxtJS / ExpressJS app on Heroku and the nuxt build command is failing throwing WebpackOptionsValidationError:

Stack trace:

nuxt:build Building... +0ms [AXIOS] Base URL: https://now-staging.hl.com/ , Browser: https://now-staging.hl.com/ nuxt:build App root: /Users/aslam/Work/hl-student-web +0ms nuxt:build Generating /Users/aslam/Work/hl-student-web/.nuxt files... +0ms nuxt:build Generating files... +5ms nuxt:build Generating routes... +17ms nuxt:build Building files... +26ms WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.module.rules[2].use should be one of these: non-empty string | function | object { loader?, options?, query? } | function | [non-empty string | function | object { loader?, options?, query? }] Details: * configuration.module.rules[2].use should be a string. * configuration.module.rules[2].use should be an instance of function. * configuration.module.rules[2].use should be an object. * configuration.module.rules[2].use should be one of these:

Complete stacktrace: https://gist.github.com/aslam/b1e4bfb4a8c07ce158dd44ccaafdaea1

My nuxt.config.js is the following:

module.exports = { router: { middleware: ['namespace', 'check-auth'] }, head: { title: 'HL Student - Web', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: 'Nuxt.js project' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }, { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' } ] }, loading: { color: '#3B8070' }, build: { vendor: ['vuetify', 'vuelidate'] }, modules: [ '@nuxtjs/pwa', '@nuxtjs/component-cache', ['@nuxtjs/axios', { baseURL: 'https://now-staging.hl.com/', credentials: false, requestInterceptor: function _reqInterceptor (config, { store }) { if (store.getters.accessToken) { config.headers.common['Authorization'] = 'Bearer ' + store.getters.accessToken } return config } }] ], plugins: [ '~plugins/vuex-router-sync.js', '~plugins/vuetify.js', '~plugins/vuelidate.js', '~plugins/firebaseConfig.js' ], css: [ { src: '~assets/style/app.styl', lang: 'styl' }, { src: '~assets/style/typography.scss', lang: 'scss' } ] }

Versions:

"node": "6.11.0", "npm": "3.10.10", "yarn": "0.27.5"

The build is failing on Heroku. Any pointers appreciated.

Categories: Software

how to destroy all the data of the current page

Sat, 2017-08-26 23:19

in my page , I have a real-time chart which updates every 3 seconds I used setInterval(function(){...} , 3000) for make the chart updates. but my problem is when I move to another page(by javascript) every thing are destroyed except my interval , so when I back to the chart page , it load every thing again and setInterval method works twice on every 3 seconds which makes duplicated points on mu chart.

this is destroy method every line works except the myInterval one

destroy() { this.num=0; this.c=0; this.startLive = false; clearInterval(this.myInterval); }

my problem appears just when I go to another page then back.

Categories: Software

How to correctly use "scoped" styles in VueJS single file components?

Sat, 2017-08-26 21:16

Docs on VueJS states that "scoped" should limit styles to the component. But if I create 2 components with same "baz" style, it will leak from one component into another:

foo.vue

<template> <div class="baz"> <Bar></Bar> </div> </template> <style scoped> .baz { color: red; } </style>

bar.vue

<template> <div class="baz">bar</div> </template> <style scoped> .baz { background-color: blue; } </style>

I expect that "baz" will be different in both components. But after generating a web page I can see yje red text on blue background, that means that "foo"'s scoped style affects "bar" component. The generated code looks like this:

<div class="baz" data-v-ca22f368> <div class="baz" data-v-a0c7f1ce data-v-ca22f368> bar </div> </div>

As you can see, the "leak" is intentionally generated by VueJS via specifying two data attributes into "bar" component. But why?

Categories: Software

Show plain HTML before Vue.js loads

Sat, 2017-08-26 21:10

I have an avatar widget built with Vue.js on a sidebar in my app. It takes a split-second to load and this causes the sidebar to jank. Is there a way that I can show plain HTML in place of the Vue app while it is loading? Basically the opposite of v-cloak.

Categories: Software

How toss Vue's transpiling to es5

Sat, 2017-08-26 19:20

The Vue cli typically transpiles es6 to es5 with babel and webpack.

Is there a Vue cli built template or template option that just transforms the .vue files correctly but does not run babel to convert the code to es5? And does not bundle?

My goal is to simply transpile the .vue files and I'll do the rest to integrate the results into my es6 + modules workflow.

Note: I tried using the "simple" cli template but couldn't find documentation on how to use it.

Categories: Software

Vuejs 2 missing request headers on one route only

Sat, 2017-08-26 17:01

I have two components called Employees and UserProfile. The first one lists an array of users, the second one shows the user's details.

Problem is when I call the server in order to get the user details no custom headers are applied to the http call. I have no issues with the call to get multilple resources.

The headers I want to add are the headers related to the CORS requirements and one header for Authorization.

I paste here the two methods.

Method fetchData in Employees component (working):

fetchData: function () { this.$http.get( process.env.BASE_API_URL + '/api/user', { headers: { 'Authorization': 'Bearer ' + store.getters.getToken } } ).then(response => { this.employees = response.body }).catch(error => { console.log(error) }) }

Headers generated:

enter image description here

Method fetchData in UserProfile component (NOT working):

fetchData: function () { this.user.id = this.$route.params.user_id this.$http.get( process.env.BASE_API_URL + '/api/user/' + this.user.id, { headers: { 'Authorization': 'Bearer ' + store.getters.getToken } } ).then(response => { this.user = response.body }).catch(error => { console.log(error) }) }

Headers Generated:

enter image description here

Also the two components are called in the router as follows:

{ path: '/employees', name: 'Employees', component: Employees }, { path: '/employees/:user_id', name: 'UserProfile', component: UserProfile }

Any suggestions?

Categories: Software

Set up vue js without npm

Sat, 2017-08-26 15:15

How can I set up vue js without npm? I'm not able to install npm right now because of some reasons. Is vue.js enough? What am I missing?

P.S.: I've just started to learn vue.js and I don't want to miss something and struggle after I realize I need something that I can get only with npm.

Categories: Software

Vue js 2 table sorting

Sat, 2017-08-26 13:02

I am trying to create a sortable table by using Vue js 2. I have already generated a table, and now just wondering how to sort this table. Thank you for your help in advance.

Please see below my code

<thead> <tr> <th class="table-header">Metric</th> <th class="table-header" v-for="metric in metricList"><a href="#">{{metric}}</a></th> </tr> </thead> <tbody> <template v-for="item in metricItem"> <tr> <td class="table-cell" style="font-weight:bold"> {{ item }}</td> <template v-for="metric in metricList"> <td class="table-cell"> {{getData[item][metric]}} </td> </template> </tr> </template> </tbody> <script> import { mapGetters, mapMutations } from 'vuex'; export default { name: 'scores', data(){ return { metricList : ["Current", "Min", "Avg", "Max"], metricItem : [ 'Happiness Score', 'Sadness Score' ] } }, computed: { ...mapGetters ([ 'getData', //getter to get data ]) } }

and the data set is something like this

getData { Happiness Score { Min : 62, Max : 154, Avg : 103 Current : 100 }, Sadness Score { Min : 66, Max : 54, Avg : 73 Current : 45 },

}

Hi guys, I am trying to create a sortable table by using Vue js 2. I have already generated a table, and now just wondering how to sort this table. Thank you for your help in advance.

Categories: Software

modal is just draggable top and bottom not to the sides

Sat, 2017-08-26 12:50

I am working with vue-js-modal and i already builded my modal and it is working well except i can't move the modal to the sides, just top and bottom if i try to move it to the left or right it doesn't move.

Basicly i followed the inscructions on the github repo.

At the begin i installed the vue-js modal and in my main.js i set it up like this:

import VModal from 'vue-js-modal' Vue.use(VModal, { dialog: true })

then on my component i call it like this:

<modal name="modalSection" @closed="checkClose" :draggable="true"> <component :is="getView"> </component> </modal>

my hide and show is working well, so i don't need to show it here, the draggable = true just allows me to drag it top and down, i thaught it has something to do because i set bootstrap up and maybe it is inside the grid in a specific col, but i checked it and it doesn't.

Any help?

Thanks

Categories: Software

Bootstrap nav-pills dynamic data changes in vue js 2

Sat, 2017-08-26 10:05

The jsfiddle was, https://jsfiddle.net/r6o9h6zm/2/

I have used bootstrap nav pills in vue js 2, to display the data based on the selected tab (i.e, if click over the standard non ac room, the record of that particular room need to be displayed) but here i am getting all the three rooms at instance and i have used the following to achieve it, but it gives no result.

Html:

<div id="app"> <div class="room-tab"> <ul class="nav nav-pills nav-justified tab-line"> <li v-for="(item, index) in items" v-bind:class="{'active' : index === 0}"> <a :href="item.id" data-toggle="pill"> {{ item.title }} </a> </li> </ul> <div class="room-wrapper tab-content"> <div v-for="(item, index) in items" v-bind:class="{'active' : index === 0}" :id="item.id"> <div class="row"> <div class="col-md-8"> <div class="col-md-4"> <h3>{{item.title}}</h3> <p>{{item.content}}</p> </div> </div> </div><br> </div> </div>

Script:

new Vue({ el: '#app', data: { items: [ { id: "0", title: "Standard Non AC Room", content: "Non AC Room", }, { id: "1", title: "Standard AC Room", content: "AC Room", }, { id: "2", title: "Deluxe Room", content: "Super Speciality Room", }, ], } })

How can i get the result with records of only selected room type and others needs to be hidden?

Categories: Software

Delete confirmation with Sweet alert in Vue js

Sat, 2017-08-26 05:37

I have a comment delete button in vue components.

<button class="button" style="background-color: grey;" @click="destroy">Delete</button>

When the button clicked will call the method "destroy"

destroy(){ swal({ title: "Delete this comment?", text: "Are you sure? You won't be able to revert this!", type: "warning", showCancelButton: true, confirmButtonColor: "#3085d6", confirmButtonText: "Yes, Delete it!", closeOnConfirm: true }, function(){ axios.delete('/comment/' + this.comment.id + '/delete'); $(this.$el).fadeOut(300, () => { return toastr.success('Comment deleted.'); }); }); },

i expect when alert come out, if users clicked confirm button then process to delete, but seem like when user clicked the delete function are not executed. What is the problems here?

Categories: Software

How to load a resource on the client side only in Nuxt.js

Sat, 2017-08-26 00:11

I'm trying to build an app using Tone.js on top of Nuxt.js. Tone.js requires the browser's Web Audio API and as Nuxt renders stuff on the server side my build keeps failing.

Nuxt addresses this in the plugin documentation and I've followed that approach in my nuxt.config.js file writing:

module.exports = { plugins: [{src: '~node_modules/tone/build/Tone.js', ssr: false }], }

however that results in this error: [nuxt] Error while initializing app TypeError: Cannot read property 'isUndef' of undefined. Looking at Tone's source I'm pretty sure this is because I'm getting it because the code is still being executed on the server side.

I've seen solutions putting the js file into the static folder and checking process.browser but both result in Tone being undefined.

My question seems to be the same as this one if it's helpful additional context

Categories: Software

Table cell validation in vuejs and laravel 5.4

Fri, 2017-08-25 23:40

I’m very new to VUE and trying loop through dynamically created tables from unique arrays. I have the table creation complete and dynamic table id’s based off a value from the array. I’m trying to validate that either cell[0] in each row contains a specific string or if the last cell[?] which has a select dropdown has been selected and is said string.

I’ve done something similar before in JS like this.

$("#" + t_node + " :selected").each(function (i,sel) { .....///code }

and like this

$("table#"+t_node+" > tbody > tr").each(function(row, tr) { .....///code }

I don’t know how to replicate with VUE. I have a onclick event that once all tables are created the onclick will loop through and validate each table.

Categories: Software

Can someone get this example vue.js app to work with techan.js?

Fri, 2017-08-25 22:35

I'm pretty sure it has something to do with babel, webpack and d3. I'm trying to get techanjs (http://techanjs.org) to work with vue.js (http://vuejs.org)

Here is an example app. https://github.com/chovy/techan-vue

You can checkout the repo and load up the app with:

git clone https://github.com/chovy/techan-vue cd techan-vue npm install npm run dev

As you can see the chart loads but you get errors in the console when you move your mouse around. From my understanding this might be due to d3 live event binding and using babel with webpack but so far I have not found a solution to the problem.

Here is the error:

Uncaught TypeError: Cannot read property 'sourceEvent' of null at __webpack_exports__.a (eval at <anonymous> (renderer.js:2455), <anonymous>:6:26) at __webpack_exports__.a (eval at <anonymous> (renderer.js:9334), <anonymous>:7:99) at SVGRectElement.eval (eval at <anonymous> (renderer.js:8060), <anonymous>:2357:38) at SVGRectElement.eval (eval at <anonymous> (renderer.js:2037), <anonymous>:29:16) __webpack_exports__.a @ sourceEvent.js?354a:5 __webpack_exports__.a @ mouse.js?ab49:5 (anonymous) @ techan.js?5956:2357 (anonymous) @ on.js?519a:27 drag.js?c3c9:10 Uncaught TypeError: Cannot read property 'button' of null at SVGPathElement.defaultFilter (eval at <anonymous> (renderer.js:8340), <anonymous>:16:70) at SVGPathElement.mousedowned (eval at <anonymous> (renderer.js:8340), <anonymous>:47:32) at SVGPathElement.eval (eval at <anonymous> (renderer.js:2037), <anonymous>:29:16)
Categories: Software

Alternative for setting the srcObject

Fri, 2017-08-25 21:15

Setting the "src" attribute of the html video element does not work with Vue.js and Vuex:

<video id="myVideoEl" :src="myStreamSrc" autoplay="autoplay">

myStreamSrc is a computed value and is set in a mutation by an event handler:

AddStream: function (state, plMyStream) { state.myRTCPeerConnection.addStream(plMyStream) state.myStreamSrc = plMyStream }

When I run my application with that code, I get the following error:

HTTP “Content-Type” of “text/html” is not supported. Load of media resource http://localhost:8080/[object%20MediaStream] failed.

When I do the following:

state.myVideoEl = document.querySelector('#myVideoEl') state.myVideoEl.srcObject = payloadWithMyStream

I do not get any error and the stream is shown. The problem is, I can not use the working code snipped because the referenced elements are added later to the DOM. This code snippet does not work when I bind the html video element in a div with a v-if Vuex.js attribute. Then I just get "undefined" as a result (because the div element with the video element did not exist on page load).

Is there a difference between setting the srcObject and setting the src attribute? I thought that when I set srcObject the video element will have a src attribute, but it does not.

Is it possible to set the srcObject in the video html attribute?

For more info, please visit my theard in the Vue.js forum: https://forum.vuejs.org/t/reference-elements-when-they-rendered-with-v-if/16474/13

Categories: Software

Render HTML in Vue.js Grid

Fri, 2017-08-25 18:06

I'm currently looking at the following example: https://vuejs.org/v2/examples/grid-component.html

and my goal is to have the data be HTML that is rendered. Here's what I've tried:

// bootstrap the demo var demo = new Vue({ el: '#demo', data: { searchQuery: '', gridColumns: ['html'], gridData: [ { html: '{{{<html><div><p>test</p></div></html>}}}', name: 'Chuck Norris', power: Infinity }, { name: '<html><div><p>test</p></div></html>', power: 9000 }, { name: '<div v-html="<p>Test</p>"></div>', power: 7000 }, ] } });

This is a proof of concept before I clean up the other data points. The requirements call for having a single-column grid that has boxes as it's items, with each box being a snapshot of rendered HTML.

We don't want to have to render the HTML to images if possible. In production, the HTML will be the content html of email mailings. Everything else, code wise, is the same as the example posted in the above link.

Thanks

Categories: Software

Pages