Vuejs

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

Can I run VueJS and NodeJS or related apps on Server that doesn't have NodeJS installed?

Fri, 2017-07-28 04:38

So I'm new to Vuejs and doesn't know anything about npm, node, and other javascript apps.

I wanted to switch to VueJS so that I can take away from JQuery. Been using AdminLTE for my projects before.

I wanted to use vue-admin now since it seems to address all of my needs. However, I have specific work area situations that seems to hinder learning Vue and other JS apps, these are:

  1. The workspace folder (development) where I'm creating applications is hosted in the production server (Windows Server).
  2. I think NodeJS isn't installed in the server
  3. Adobe Coldfusion is used. I don't have a local server, so the production server is used when developing.

Question:

  1. Will the production server run the app built with vue-admin even if the production server doesn't have NodeJS installed? (I have NodeJS locally).
  2. I need to use Coldfusion for the logic of the application, specifically I'm using CFWheels right now and vue-admin for Frontend and UX. Is it possible? The application I'm making is closely related to parts of an ERP system.
  3. Any pointers on how I could do this?
Categories: Software

How to store and access data on eventBus in VueJS

Fri, 2017-07-28 03:11

Basically I want to be able to access some centralized data by setting up a dataBus as a vue instance object, and then access and tweak this data from different components.

I cant seems to access by data from my componenets, even basic string interpolation is not getting rendered to the DOM.

export const dataBus = new Vue({ data: { numQuotes: 4, stringVar: 'Hellow There' } });

I also tried setting up my data as the return of the function data(). But being as my data bus is an actual vue instance I don't think this is correct. (I could be wrong). Following is the component in which I import my dataBus and try to output my data.

<template> <div> <h1>Quotes Added</h1> <div id="trackerBar"> <div id="trackerBarActual"> <h2>{{numQuotes}}/10</h2> </div> </div> </div> </template> <script> import { dataBus } from '../main.js'; export default{ } </script>

I am getting the following error: Property or method "numQuotes" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

Am I missing something obvious? Is it even possible to access data this way? Or do I have to access it as a method?

Categories: Software

Vue is not detected when JSP is loaded through struts

Fri, 2017-07-28 01:57

Example JSP :

<!DOCTYPE html> <html lang="en-US" > <head> <script src="vue.min.js"></script> </head> <body> Sample heading <div class="container" id="mainDiv"> {{firstName}} </div> </body> <script type="text/javascript"> Vue.config.devtools = true; var app = new Vue({ el: '#mainDiv', data: { firstName: 'name', lastName: 'lName', description: 'desc' } }); </script> </html>

The following options are tried :

  1. If the above file is executed using .html, it works as expected. Chrome Dev tools detects that its a Vue application
  2. If the above file is executed using .jsp, it works as expected. Chrome Dev tools detects that its a Vue application(http://localhost:8080/example.jsp)
  3. If the above file is executed using .jsp and the jsp is loaded through form submission like http://localhost:8080/example.do and the success is redirected to example.jsp, it doesn't work.

Output in case 1 and 2 :

Sample heading
name

Output in case 3 :

Sample heading.

  • Ideally its supposed to display "name" as well.
  • If we do inspect element, it shows "".
  • In inspect element, If I select "app.firstName" I am able to see the value "name"
  • lets say, if I add "", Vue is still unable to display component's template. If I do app.$ref -- {} in case 3 and app.$ref -- {container:...} in case 1 and 2

Has anyone tried similar scenarios ? I was wondering what exactly is making Vue to not load this data.

Any help in resolving this issue is appreciated.

Thanks in advance

Categories: Software

vuejs component array push watcher

Fri, 2017-07-28 01:25

confusing title, I wasn't sure how else to write it. So i have a component and it accepts a prop which is an array. What i am looking to do, is on array.push() i would like a function to trigger for that array element.

so it is an alert toast message, and i want it to stay up for 3 seconds. so i was thinking about something like

watch: { arrayObj: function () { let self = this setTimeout(function() { self.dismiss(this.id) }, 3000) } }

but i think i may be missing something here. How do i get the latest pushed object's reference so i make sure the dismiss method calls the correct alert? Is watch even the correct way to go about this?

Categories: Software

Vue $el is undefined when testing with Mocha/Chai under meteor

Fri, 2017-07-28 01:12

I'm starting our unit test environment for our project, but we may have picked a combo that doesn't work well in a couple scenarios.

Our project runs under Meteor, the code for the UI is written in Vue and Coffeescript. The test environment we're trying to work with is Mocha & Chai. When I run the test suite, the command looks like this:

meteor test --once --driver-package=dispatch:mocha

From the examples around the internet, the following code should work:

const VueObject = Vue.extend(MyVueComponent); const VueInstance = new VueObject().$mount(); chai.assert.ok(VueInstance.$el.textContent);

From that point, I could ask $el all sorts of questions for my test, however $el is undefined. I even tried waiting by using Vue.nextTick() and it's still undefined. In the examples I've found, they often talk about using webpack, but I heard meteor doesn't like using webpack.

Does anyone have any suggestions? Did we pick a hard combination to work with?

Categories: Software

How to pass props to a vue component when it is instanciated?

Fri, 2017-07-28 01:04

I'm building a TabbedDetailView reusable component in vue. The idea is that the tab-detail component receives a list of objects which have a title and a component. It then does the logic so that when you click on a tab, then the component is loaded. The problem is that this components have a prop that is a user_id. How do I insert this prop into the components from outside of the template? For example (using single file vue components):

SomeComponent.vue

import Vue from 'vue'; import Component1 from '@/components/Component1'; const Componenet1Constructor = Vue.extend(Component1); export default { data() { return { tabs: [ {title: 'Componenent 1', detail: new Component1Constructor({propsData: {user_id: this.user_id}})} {title: 'Component 2', detail: Component2}, {title: 'Component 3', detail: Component3}, ], }; }, props: ['user_id'], } <template> <div> <tab-detail :tabs='tabs'></tab-detail> </div> </template> Component1.vue

export default { props: ['user_id'], }; <template> {{ user_id }} </template>

Running the above throws the error: [Vue warn]: Failed to mount component: template or render function not defined.

Categories: Software

Rails Vuejs Webpacker: Passing instance variable data

Fri, 2017-07-28 00:19

I am trying to learn how to build an app with Rails 5.1 with Vuejs, as generated via the Webpacker gem.

$ rails new myvueapp --webpack=vue

How do I pass instance variable data back an forth between the Vue components, to get my data in/out of the database?

Let's say for example that I have a User model with Username and Email fields. Is there a simple example of how to pass instance variable, @user, data from the controller to a component?

I believe there are two ways to do this:

(1) In the controller, has the render :json => @user and then use something like the fetch API or Axios to retrieve the data in the .vue component.

-or-

(2) Use the something like the example <%= javascript_pack_tag 'hello_vue' %> together with a <%= content_tag ... %> in a view.

When I do this <%= javascript_pack_tag 'hello_vue' %> example, I can see the "Hello Vue!" from the data in the component "message" variable, but am having trouble finding an example of instance variable data, eg: @user data, being passed in and out of Rails.

Any examples of how to pass @user data would be much appreciated.

Thank you.

Categories: Software

Laravel 5.4 + vue2 click Event Handling not working

Thu, 2017-07-27 22:47

I have problem with Event Handling in vue2 with Laravel 5.4 - nothing happen when i use click event on the button. No error or anything else.

My html (in fact its header.blade.php):

<div id="example"> <button v-on:click="exclick">Super btn</button> </div>

My js (app.js in resources/assets folder)

require('./bootstrap'); new Vue({ el: '#example', methods: { exclick: function (event) { alert("Log 1"); if (event) { alert("Log 2"); } } } }); const app = new Vue({ el: '#app' });

JS compiled by gulp

Please help!

Categories: Software

Should I be seeing hundreds of nested calls in DevTools flame charts, when I'm supposedly pre-compiling all of my Vue components?

Thu, 2017-07-27 22:35

I assumed that by refactoring all of the components in this large application into single-file Vue components, and using Webpack with Vue production runtime only, I could eliminate these deep call stacks of hundreds of nested calls that appear to be assembling a virtual DOM. It takes about 1500ms for all the scripting. If I comment out the reference to the root element (i.e. it doesn't bind), the scripting takes about 300ms. This seems expensive. The 'array' is by far the biggest part of the heap profile. Am I actually successfully pre-compiling?

Categories: Software

Rails 5.1+ Vuejs Webpacker: Normal Rails MVC vs Rails API

Thu, 2017-07-27 21:30

I am starting a new app using Rails 5.1 and Vue.js, with the built-in Webpacker Vue.js pack (generated via the --webpack=vue flag).

I am trying to understand the pros & cons of using a normal Rails MVC app vs a Rails API app (generating a Rails app with the --api flag).

$ rails new someapp --webpack=vue vs. $ rails new someapp --api --webpack=vue

Given the fact that Rails API has been merged into core since 2015, and built-in Webpack via the Webpacker gem is brand new (Rails 5.1, 2017), what would be the best way to build a Rails app, where the frontend is going to be Vuejs? Or, mostly Vuejs?

Stick to regular Rails with Webpacker Vue, or Rails API with Webpacker Vue? And what are the tradeoffs?

Some of this answer will simply come down to a conversation about full-stack MVC apps vs SPA apps with API. However, are there any specific Rails Way +Vue.js components workflow things I should consider, beyond the "this is a question of an fullstack MVC app vs. a SPA app."

I want to note that I realize that the answers are going to be somewhat stylistic preference. Some might prefer one over the other.

Both will work, but I would like to think about ease of use, compatibility and trade-offs of doing it one way verse the other.

Thank you.

Categories: Software

Vue component css being overwriten by bootstrapp-sass on Laravel

Thu, 2017-07-27 21:11

I have a almost vanilla instalation of Laravel. No matter what i do, all my scoped css inside the component is simply ignored and bootstrap-sass styles are applied instead. Example of this happening

How can i stop this from rappening?

Categories: Software

Issue calling Vue Method via Vue Computed

Thu, 2017-07-27 20:32

I believe this issue is related to JS in general as opposed to VueJS. But I have the following Vue Method that returns a Firebase Call and returns the object asked for. This is working:

methods: { getSponsor (key) { db.ref('businesses').child(key).on('value', snap => { console.log(snap.val()) return snap.val() }) } }

[Object]

Now, when I call this method from a computed property, it results in undefined:

computed: { sponsor () { console.log(this.getSponsor(key)) return(this.getSponsor(key)) } }

Undefined

Why is this? Is it because of how I return my method?

Categories: Software

Where To Place Firebase's OnAuthStateChanged-Method In A VueJS-Application?

Thu, 2017-07-27 19:59

I'd like to trigger the onAuthStateChanged-method of Firebase in my VueJS-Application.

Currently I am not able to stay logged in as a certain user, the onAuthStateChanged-method seems not to run.

my action is kicked off by ...

beforeCreate() { this.$store.dispatch('update_session') }

... in my main App-Component.

the mutation looks like:

update_session(state) { auth.onAuthStateChanged().then((user) => { if (user) { // USE USER KEY state.user.current.key = user.uid // USE USER ROLE users.child(state.user.current.key).on('value', (snapshot) => { state.user.current.role = snapshot.val().role }) } }) }
Categories: Software

Echo.private laravel 5.4 not work

Thu, 2017-07-27 19:53

i working for real-time notification .
notification send but not real-time i need to refresh page to enable receive

notification.vue

<script> import NotificationItem from './NotificationItem.vue'; export default { props: ['unreads', 'userid'], components: {NotificationItem}, data(){ return { unreadNotifications: this.unreads, } }, methods: { markNotificationAsRead() { if (this.unreadNotifications.length) { axios.get('markAsRead'); } } }, mounted() { console.log('Component mounted.'); Echo.private('App.User.' + this.userid) .notification((notification) => { console.log(asd); let newUnreadNotifications = {data: {thread: notification.thread, user: notification.user}}; this.unreadNotifications.push(newUnreadNotifications); }); } } </script> <template> <li class="dropdown" @click="markNotificationAsRead"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="glyphicon glyphicon-globe"></span> Notifications <span class="badge alert-danger">{{unreadNotifications.length}}</span> </a> <ul class="dropdown-menu" role="menu"> <li> <notification-item :key="unread.id" v-for="unread in unreadNotifications" :unread="unread"></notification-item> </li> </ul> </li> </template>

script execute all but the following code not work

Echo.private('App.User.' + this.userid) .notification((notification) => { console.log(asd); let newUnreadNotifications = {data: {thread: notification.thread, user: notification.user}}; this.unreadNotifications.push(newUnreadNotifications); });

anyone can help plz ? i searched alot but not found solution ??

Categories: Software

How should i include css files in .vue files?

Thu, 2017-07-27 19:49

I'm using official vue-cli scaffolder and trying to include normalize.css in App.vue this way

<style scoped> @import "/node_modules/normalize.css/normalize.css"; .app { font-family: Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; max-width: 1000px; margin: auto; font-size: 16px; display: flex; align-items: center; justify-content: center; min-height: 100vh; } </style>

But after compiling css doesn't include in style tag or as external file:

enter image description here

So, how can I correctly include this or another css file?

Categories: Software

The worlds simplest vue.js/vuefire/firebase app. But can't read value

Thu, 2017-07-27 19:38

Vue.js is a bit of a life style change for a sql programmer, but getting there. Here I use vuefire as per specs, even manually inserting the correct key from my one record, one field Firebase DB to test it out. Yet see nothing returned or displayed.

Love to know how to do that! And fill in my one value form. From there the sky's the limit I'm sure. Thanks for any help.

ERROR MESSAGE: vue.common.js?e881:481 [Vue warn]: Error in mounted hook: "ReferenceError: residentsArray is not defined"

<template> <div class="edit"> <div class="container"> <p style="margin-bottom:10px;font-weight:800;">EDIT RECORD</p><br> <form id="form" v-on:submit.prevent="updateResident"> <fieldset class="form-group"> <label for="first_name">Name</label> <input type="text" class="form-control" id="first_name" name="first_name" v-model="currentResident.name"> </fieldset> <input type="submit" class="btn btn-primary" value="Add New Resident"> </form> </div> </div> </template> <script> import firebase from 'firebase' let editConfig = { apiKey: "123456789", authDomain: "myapp.firebaseapp.com", databaseURL: "https://myapp.firebaseio.com", projectId: "my", storageBucket: "myapp.appspot.com", messagingSenderId: "1234567890" }; var firebaseApp = firebase.initializeApp(editConfig, "Edit") var db = firebaseApp.database() let residentsReference = db.ref('residents') export default { name: 'Edit', mounted() { this.currentResident.name = residentsArray.name; }, firebase: { residentsArray: residentsReference.child('-KpzkbA6G4XvEHHMb9H0') }, data () { return { currentResident: { name: '' } } }, methods: { updateResident: function () { // Update record here } } } </script>
Categories: Software

Uncaught Error: [vue-router] "path" is required in a route configuration

Thu, 2017-07-27 19:25

I'm following the official example but I don't know why I get a blank page with this js error

vue-router.esm.js?fe87:10 Uncaught Error: [vue-router] "path" is required in a route configuration.

Here is my two pages:

/:language/bar /:language/foo +------------------+ +-----------------+ | +---------+ | | +---------+ | | | header | | | | header | | | +---------+ | | +---------+ | | +--------------+ | | +-------------+ | | | bar | | +------------> | | foo | | | | | | | | | | | +--------------+ | | +-------------+ | +------------------+ +-----------------+

And this is how I'm trying to do it.

My entrypoint js file:

import Vue from 'vue'; import router from './router'; // import some components let vm = new Vue({ el: '#app', router, components: {/*imported components*/}, }); vm.$language.current = vm.$route.params.language;

My entrypoint html

<body> <div id="app"> <!-- this is the header, the common part --> <navbar fullname=''></navbar> <router-view></router-view> </div> </body>

My router

import Vue from 'vue'; import Router from 'vue-router'; // import foo and bar components Vue.use(Router); let routes = [ { path: '/:language', name: 'homepage', children: [ { path: 'foo', component: Foo }, { path: 'bar', component: Bar }, ] } ]; export default new Router({routes,});

My foo component

<template> <div> <h1>FOO</h1> </div> </template> <script>export default {};</script>

How do I fix this error?

Categories: Software

Update template with model changed from input vueJS

Thu, 2017-07-27 17:29

I'm developing my first app in vueJs and laravel. now I 'have a problem with v-model. I have a page with component Person that edit or create new Person. So I get from my backend in laravel or Model Person or new Person.

Now in my frontend I pass data to component by props:

Page.blade.php

<Person :person-data="{!! jsonToProp($person) !!}"></Person>

(jsonToProp transform model coming from backend in json) In this case, I would return new Model so without properties, so $person will be a empty object.

Person.vue

<template> <div> <label for="name_p"> Name</label> <input id="name_p" v-model="person.name" class="form-control" /> <button v-on:click="test()">test</button> {{person.name}} </div> </template> <script> export default { props: ['personData'], mounted() { }, data() { return { person: this.personData } }, methods:{ test(){ console.log(this.person.name); } } } </script>

Now if I change input with model v-model="person.name" I would print name in template but it doesn't change. But if I click buttonit console write right value. So I read that changing model value is asynch, so How I can render new Model when change input?

Categories: Software

How to get href attributr value in vue.js

Thu, 2017-07-27 16:36

I am new to vuejs and I am having a query i.e. How can we get the href attribute value of a HTML variable.

<pre> var custompath = '<a id="myid" href="undefined111">a8AZCtgt</a>' </pre>

Thanks in advance

Categories: Software

Vue - any way to reuse SLOT?

Thu, 2017-07-27 16:24

Im working on responsive Vue.js app with Uikit. I must create 2 menus - one for desktop version, one for mobile. So I must define same menu items 2 times, first for desktop links slot, second time for mobile. I dont want define it 2x. How can I deal with this problem elegantly? Any ideas?

<template id="app"> <app-layout> <template slot="navlinks-desktop"> <router-link to="/link1" tag="li" exact><a>Link 1</a></router-link> <router-link to="/link2" tag="li" exact><a>Link 2</a></router-link> </template> <template slot="navlinks-mobile"> <router-link to="/link1" tag="li" exact><a>Link 1</a></router-link> <router-link to="/link2" tag="li" exact><a>Link 2</a></router-link> </template> <transition name="fade" slot="content"> <router-view></router-view> </transition> <p slot="footer">Footer text</p> </app-layout> </template> <template id="app-layout"> <div class="main-container"> <header class="uk-margin-bottom"> <nav class="uk-navbar uk-navbar-attached"> <div class="uk-navbar-brand uk-hidden-small">My Application</div> <div class="uk-navbar-flip"> <ul class="uk-navbar-nav uk-hidden-small"> <slot name="navlinks-desktop"></slot> </ul> <div class="uk-navbar-toggle uk-button-dropdown uk-visible-small uk-dropdown-close" data-uk-dropdown="{mode: 'click'; justify: 'nav'}"> <div class="uk-dropdown uk-dropdown-navbar uk-dropdown-small"> <ul class="uk-nav uk-nav-dropdown"> <slot name="navlinks-mobile"></slot> </ul> </div> </div> </div> <div class="uk-navbar-brand uk-navbar-center uk-visible-small">My Application</div> </nav> </header> <div class="uk-container uk-container-center"> <main> <slot name="content"></slot> </main> </div> <footer class="uk-text-center fixed-bottom"> <slot name="footer"></slot> </footer> </div> </template>
Categories: Software

Pages