Vuejs

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

Vue template not where should

Mon, 2017-07-24 13:07

My tr witd td's are not in my table... why? They are out of the table. I don't know why.

My view:

<table class="table-responsive"> <todo-list v-for="todo in todos" v-bind:todo-obj="todo" v-bind:key="todo.id" :todoObj.sync="todo" v-on:usun="deleteTod"></todo-list> </table>

And here is my component:

Vue.component('todoList', { props: ['todoObj'], template: '<tr>' + '<td><div class="round"><input id="todoObj.id" type="checkbox" v-on:click="toggle" v-model="todoObj.done" /><label for="todoObj.id"></label></div></td>' + '<td class="textTodo">{{todoObj.description}}</td>' + '<td><button v-on:click="deleteTodo" class="btn-xs btn-danger">delete</button></td>' + '</tr>',

And second problem is that my checboxes are not working. They looks fine, but they don't want to toggle... They only react when checking the first row from table. Why?

Categories: Software

vue js isotope with packery layout-mode

Mon, 2017-07-24 12:06

I'm using vue-isotope component from https://github.com/David-Desmaisons/Vue.Isotope

I'd like use layout-mode: 'packery' and I have installed the node module packery. So I have imported this module in my file vue but dosn't work, like this:

import isotope from 'vueisotope' import 'packery

Any ideas? Thanks

Categories: Software

How to publish an Vue.js NPM package with a Vuex module?

Mon, 2017-07-24 12:06

I am developing some Vue components that I would like to place in an NPM package. The problem that I am facing is that I have no idea how to publish components that rely on a Vuex module.

I have neatly placed all the code needed for this library of components into a separate Vuex module but how do I register my module when somebody imports my package?

A good start would be creating a plugin I guess but I would still need to check for a Vuex instance and somehow register my module.

I've seen plenty of tutorials on how to publish Vue components but not something more complex.

Any suggestions?

Categories: Software

Display multiple json objects from a nested json to a cell data in Vuetable

Mon, 2017-07-24 11:45

I'm currently using Vuetable-2 to display data from my server.

Is there a way to display multiple json objects from a nested json to a a cell data in Vuetable?

Response payload from server: enter image description here

Current Table Format: enter image description here

Expected result:

enter image description here

Categories: Software

x-editable on vuejs doesn't appear

Mon, 2017-07-24 11:14

I'm trying to use x-editable on a VueJs file inside of a symfony project. So what I did is first i went on http://cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.1/bootstrap3-editable/js/bootstrap-editable.min.js

and copy the content in a file

/path/to/file/web/js/xeditable/bootstrap3-editable/js/bootstrap-editable.min.js

I also have a file

path/to/file/web/js/xeditable/bootstrap3-editable/css/bootstrap-editable.css

In my vue I have :

<span href="#" id="productName"> {{{ product.name }}} </span> <script> $( "#productName" ).editable(); import js from "path/to/file/web/js/xeditable/bootstrap3-editable/css/bootstrap-editable.css"; import xeditable from "/path/to/file/web/js/xeditable/bootstrap3-editable/js/bootstrap-editable.min.js" export default { [...] components: {xeditable} [...]

But nothing happend

Categories: Software

mergeData error when using Vue Grid Layout?

Mon, 2017-07-24 10:58

I am using Vue and Vue Grid Layout to make a dashboard application. When the user connects to the application with his account, his widgets are retrieved from a MongoDB database and displayed on the Home page with vue grid layout.

The error doesn't occur on first load, but always occurs when the user navigates through an other page (using Vue router) like his profile or settings, and then returns to the Home Page. Vue router doesn't seem to be the problem as the URL changes.

The error seems to be from Vue Grid Layout since when i comment the code the error doesn't appear.

Here is the exact error : Screenshot

Thanks in advance,

Categories: Software

Passing method event handling in Vue.js

Mon, 2017-07-24 10:47

I am very new to Vue.js and wrapping my head around method event handling.

What my function is doing is to read a barcode using web camera input and display its raw content.

The function works fine if I just render the raw content. However, if I try to transform the raw content to a more readable form. I am getting the following error:

TypeError: Cannot read property '1' of null when calling formatBarcode method.

I am pretty sure it's probably not even related to Vue.js in particular but a common JS problem.

html

<div id="scan"> <div class="row m-b-1"> <div class="col-sm-6"> <video id="preview"></video> <h5>Camera</h5> <ul> <li v-for="camera in cameras"> <span v-if="camera.id == activeCameraId" :title="formatName(camera.name)" class="active">{{ camera.name }}</span> </li> </ul> </div> <div class="col-sm-6"> <h5>Scans</h5> <transition-group name="scans" tag="ul"> <li v-for="scan in scans" :key="scan.date" :title="scan.content">{{ formatBarcode(scan.content) }}</li> </transition-group> </div> </div> </div>

JS

var app = new Vue({ el: '#scan', data: { scanner: null, activeCameraId: null, cameras: [], scans: [] }, mounted: function() { var self = this; self.scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 }); self.scanner.addListener('scan', function(content) { self.scans.unshift({ date: +(Date.now()), content: content }); }); Instascan.Camera.getCameras().then(function(cameras) { self.cameras = cameras; if (cameras.length > 0) { self.activeCameraId = cameras[0].id; self.scanner.start(cameras[0]); } else { console.error('No cameras found.'); } }).catch(function(e) { console.error(e); }); }, methods: { formatBarcode: function(content) { const regex = /(01)(\d{14}|\d{0}})(21)(\d{10}|\d{0})/g; let m; while ((m = regex.exec(content)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } } return `Group1: (${m[1]}) ${m[2]} Group: (${m[3]}) ${m[4]}`; } } });

This is the regex I'm trying to test https://regex101.com/r/SvCs5t/3

Working fiddle to test the regex transformation https://jsfiddle.net/o01474u2/

Categories: Software

Walkthrough on Onsen -vue

Mon, 2017-07-24 10:46

How to load walkthrough component first among other component on the render method of vue?

import AppNavigator from './AppNavigator.vue'; import CustomToolbar from './partials/CustomToolbar.vue'; import WalkThrough from './pages/WalkThrough.vue'; Vue.use(VueOnsen); Vue.component('custom-toolbar', CustomToolbar); const app = new Vue({ el: '#app', render: h => h( AppNavigator //What I want to do is to load first walkthrough before loading the AppNavigator ) });
Categories: Software

Setting an active state with Vue JS and for loop

Mon, 2017-07-24 09:48

I have a list of strings in Vue, and I'm using v-for to list all of them in "list-group" with bootstrap. I want to set the "active" state on click on one of the items, but I can't find a way to ID a specific item on the list with the for loop.

HTML - <div class="list-group" id="ServersList"> <a href="#" class="list-group-item" v-for="Server in Servers">{{Server.text}}</a> </div>

VueJS - var ServersList = new Vue({ el: '#ServersList', data: { Servers: [ { text: '1' }, { text: '2' }, { text: '3' }, { text: '4' }, { text: '5' }, { text: '6' } })

Thanks!

Categories: Software

Vue.js code doesn't work on a html without cdn

Mon, 2017-07-24 09:21

I'm new to Vue.js and i have a header html which doesn't have cdn link of Vue.js.

<nav class="navbar navbar-toggleable-md navbar-inverse"> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="containerNav"> <div class="row"> <div class="col-6"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="navbar-brand" href="#"><img src="images/logo.png" height="30"/></a> </li> <li class="nav-item active"> <a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="login.html">TestPage</a> </li> </ul> </div> <div class="col-5" id="login-App"> <ul class="navbar-nav float-right"> <li class="nav-item"> <a class="nav-link" href="#">{{data.user}}</a> </li> <li class="nav-item"> <a class="nav-link" onclick="cleanLocalStorage()" href="login.html">Log out</a> </li> </ul> </div> </div> </div> </div> </nav>

I load this header html with jquery document.ready function.

$(document).ready(function () { $(".footer").load("./footer.html"); $(".header").load("./header.html"); });

Thererefore i cant show Vue.js variable on the page. Here is my Vue.js code

var loginApp = new Vue({ el: '#login-App', data: function () { return { data: {} } }, methods: { fetchData: function () { Vue.set(loginApp.data, 'user', JSON.parse(localStorage.getItem('user')).name); } } });

If i use cdn link on header html, it works, but i prefer to use only on index page. Is there any trick for this situation? Should i use Vue.js CLI instead of cdn?

Categories: Software

Get data from nested json and display using Vue-Multiselect

Mon, 2017-07-24 08:30

Basically what I want to achieve is GET data from server and display the data in the nested json to display in Multiselect, Vue-Multiselect

I'm able to get the objects from the nested json to display in multiselect, but I'm not sure how to customize it to only show the name.

Current behaviour: enter image description here

So expected behaviour would be, only Sofa, Table and Chair should be shown in the multiselect: enter image description here

Is there a way for me to only display like the picture above?

Thank you for your help!

Categories: Software

vue js 2: Access props in mounted function

Mon, 2017-07-24 07:58

I have data props in child components. Inside child component on mounted function I need to get specific value from props and set select dropdown value. I am using vue-multiselect plugin which is working fine. Here is the code.

module.exports = { props: ["Subscriptions"] mounted: function () { let vm = this; Vue.nextTick(function () { // I want to access props here but it return 0 length array console.log(vm.$parent.Subscriptions); }); }, beforeUpdate() { let vm = this; console.log(vm.$parent.Subscriptions); }, // updated() { // let vm = this; // console.log(vm.$parent.Subscriptions); // } };

Now only time I do get subscriptions is in beforeUpdate and updated function but this called each time there is a change in value which is not required. I only need to change it first time in order to set drop down initial value.

Categories: Software

attaching css class to ID's in a vue app

Mon, 2017-07-24 05:00

First time SO poster here; I'm having some trouble with attaching a css class to an element with an ID; the way i'm doing it with classes is i have a click event on an HTML element that triggers a property to toggle state, and that property returns the new class, which works great.

When doing this and targeting an ID, i'm not too sure what i'm missing; I can get the click event to toggle state, but i'm not sure how to attach a class to that element ID. I've pasted the codepen below; thank you in advance.

https://codepen.io/KarimPremji/pen/vJYKWB

<!-- testing ID binding--> <div id="excerciseID" @click="turnPink = !turnPink" :class="divClassesPink"></div> <br>TurnPink state: {{turnPink}} </div> new Vue({ el: '#app', data: { turnRed: false, turnPink: false }, computed: { divClassesRed: function(){ return { red: this.turnRed, blue: !this.turnRed } }, divClassesPink: function(){ return { pink: this.turnPink, blue: !this.turnPink } } }})
Categories: Software

Show loading property on Pageload with nuxt

Mon, 2017-07-24 01:57

I have a nuxt project that is working well. However on the loading of the page a async method is performed.

import charge from '~plugins/charge' export default { asyncData (context, callback) { const subscription = context.params.id; charge.getAll(subscription, function(result){ let data = result.data;; callback(null, data) }); } }

My Problem is, that the page stays with until the async operation has been performed. How can i Show a loader until the function returns a result?

Categories: Software

how can i set old input value on refresh in Vuejs

Mon, 2017-07-24 01:23

im using laravel and Vuejs

how can i set the input old value on refresh or back to the page in vue dynamic component

something like this :

value="{{ old('name') }}
Categories: Software

Vue & Webpack: Setting development and production variables

Mon, 2017-07-24 00:43

I'm using vue-cli to build my web app. My app uses an api in a number of places like so:

axios.post(API + '/sign-up', data).then(res => { // do stuff });

The API variable is a constant containing the beginning of the address, e.g., https://example.com.

How would I detect whether this is a dev or prod build and set that variable accordingly? For now, I have a script tag in my index.html document and I am manually changing it for dev and prod:

<script>var API = 'https://example.com'</script>

Is there a better way to handle this?

Categories: Software

Why importing the Vue.js source works, but not the module?

Sun, 2017-07-23 22:47

The following HTML code

<!DOCTYPE html> <html lang="en"> <body> Greeting below: <div id="time"> {{greetings}} </div> <script src='bundle.js'></script> </body> </html>

together with the entry.js file

// either the import or the require work Vue = require('./vue.js') //import Vue from './vue.js' new Vue({ el: "#time", data: { greetings: "hello world" } })

and the webpack.config.js

module.exports = { entry: './entry.js', output: { filename: 'bundle.js' } }

works fine (vue.js is locally downloaded from the site or a CDN).

I then tried to use the vue module installed via npm install vue --save-dev by changing entry.js to

import Vue from 'vue' new Vue({ el: "#time", data: { greetings: "hello world" } })

This version does not work anymore: the whole <div> is not rendered (only Greeting below is displayed).

What should be done so that Vue.js can be used with webpack?

The Vue documentation mentions webpack a few times, but only in the context of components or production builds.

Categories: Software

Should two-way binding work in vue when casting the value with the `.number` modifier?

Sun, 2017-07-23 21:52

This is what my HTML looks like:

<div v-for='(notUsingThis, index) in numbers'> <NumberWrap :index="index" :numbers="numbers" /> </div>

in NumberWrap.vue

<input type='number' number v-model.number='model' />

I have a getter/setter there, I see the setter being called every time I change the value. However the second the field loses focus, it resets to nothing.

set model(val) { console.log('setting', val); this.numbers[this.index] = val; } get model() { console.log('getting', this.numbers[this.index]); return this.numbers[this.index]; }

If I log out my object in the console, I see it has been updated but the field is not showing it. If I remove the .number modifier it works as expected.

I know it seems indirect, but this is a simplification of how the code works.

Is there special handling I need to do myself when working with the casting? Is there anything that explicitly wrong with the way I use model get/set?

Categories: Software

How to initialise components when using dynamic components

Sun, 2017-07-23 20:12

I have this code:

<div id="blocks"> <component v-for="block in blockList" :is="block.component" :id="block.uniqueId" :init-show-header="showHeaders" v-model="block.model" v-on:content-block-remove="removeBlock" :key="block.uniqueId"> </component> </div> addBlock(name) { let block = new Object() block.model = new Object() block.uniqueId = name + '-block-' + this.blockCount block.component = name + '-block' this.blockList.push(block) this.blockCount = this.blockCount + 1 }, <div id="buttons"> <button v-on:click="addBlock('taxonomy')" type="button" name="button" class="btn btn-primary btn-sm">Add Taxonomy</button> <button v-on:click="addBlock('text-input')" type="button" name="button" class="btn btn-primary btn-sm">Add Text Input</button> <button v-on:click="addBlock('header')" type="button" name="button" class="btn btn-primary btn-sm">Add Header</button> <!-- <button v-on:click="addBlock('text')" type="button" name="button" class="btn btn-primary btn-sm">Add Text</button> -->

I have different types of components that have different kind of options stored in data object. I plan to save these options to the database upon saving the page where they are added and their settings adjusted. Each component type, its order on the page and components options are going to be saved in the database.

My question is, how do I initialise this page again after refreshing it and getting all the components and their options from the database? How would I get the options to each component when adding them in a loop on a mount event of the parent component where I load all components saved in the database and want to render them with the correct options?

What are my options?

Categories: Software

Efficient ways to structure a main site + admin panel with vue-router?

Sun, 2017-07-23 20:08

What I am trying to accomplish is pretty straightforward. I want to have a set of main routes, e.g. '/', '/contact', '/blog', which all serve content from a database. At the same time, I need a set of routes which will be password-protected, e.g. '/admin/list', '/admin/add'.

My issue is that with the vue-cli and webpack combination, there is only one index.html, meaning that my admin panel and main site will be sharing the same meta tags, and CSS/JS files I include into index.html.

How would I go about serving a different .vue file to be used for div#app, depending on the current route? Apologies if this is something that's painfully easy to do. I'm just trying to figure out if there's a way to, more or less, 'host' two linked apps within the same routing engine.

This is a more 'visual' representation of what I'd do currently, but I feel like I'm missing something.

<app> <main> <main-nav/> <main-content/> <main-footer/> </main> <admin> <admin-nav/> <admin-content/> </admin> </app>

Is there a way to do something like this with the Vue routing engine, where the HTML is very, very different for both 'apps'?

<main-app> <main-nav/> <main-content/> <main-footer/> </main-app> <admin-app> <admin-nav/> <admin-content/> </admin-app>

Thanks for your time!

Categories: Software

Pages