Vuejs

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

@/components/<routeName>View

Wed, 2017-07-19 17:58

I refer to the code below from electron vue. the @ symbol means this. or window from Does the '@' symbol have special meaning in Javascript, Coffeescript or Jquery? Is it the same??

{ path: '<routePath>', name: '<routeName>', component: require('@/components/<routeName>View') }
Categories: Software

Multiple filters applied to array of objects

Wed, 2017-07-19 17:31

In one of Vue my components I have code that looks like this

<li class="comment" v-for="comment in comments"> ... </li>

And my computed method

computed: { comments() { // All filter UI elements are associated with a filter method // and when the user interacts with an element of the UI, filtersToApply gets populated with // the associated method. Not too important right now, // it just checks whether user interacted with the UI or not, so it could essentially be a boolean. But I plan to make use of the functionality at a later time. const filtersToApply = this.filtersToApply(); // if user hasn't interacted with the filter UI, just return the comments // else, apply filter(s) to comments if (filtersToApply.length === 0) { return this.$store.getters.comments; } else { return this.applyFilters(this.$store.getters.comments); } }

Ultimately, I want to do something like this:

// Apply the filters to the comments, one by one applyFilters(comment) { return this.filterByX() .then(this.filterByY) .then(this.filterByZ) .... }

where the filter methods look like

filterByX(comments) { return new Promise((resolve, reject) => { ....... resolve(comments) }) }

How could I make this work? And is it a good pattern?

Categories: Software

v-select doesn't recognize label prop

Wed, 2017-07-19 16:49

I'm working on a VueJs file and try to use <v-select> so what I'm doing is that :

<v-select :options="divisions" label="text" ></v-select>

and my divisions is an array of object conatining id and text but when i'm going on my page I have <% getOptionLabel(option) %> instead of the text value for each one of my divisions value

here is a screenshot of console.log(this.divisions) : enter image description here

Categories: Software

Vue won't recognize recursive component

Wed, 2017-07-19 16:40

I'm trying to list the comments (Comment.vue) of a topic (TopicDetail.vue). My two components looks like this:

The Comment Component

<template> <div> <li> {{ commentDetails.by.name }} <p> {{ commentDetails.content }} </p> </li> </div> </template> <script> export default { name: 'comment', props: { comment: Object }, data() { return { commentDetails: [] } }, methods: { fetchComment: function() { this.$http.get('http://localhost:1337/comments/' + comment.id).then(response => { this.commentDetails = response.body; }) } }, mounted() { this.fetchComment(); } } </script> <style type="text/css" media="screen"> </style>

And for my TopicDetail component:

<!-- Topic Detailed view --> <template> <ul class="collection with-header"> <comment v-for="(comment,key) in comments" :comment="comment" :key="comment.id" ></comment> </ul> </template> <script> import Comment from './Comment.vue' export default { name: 'topic-detail', data() { return { loading: true, topic: [], comments: [] } }, component: { Comment }, methods: { fetchTopic: function() { this.$http.get('http://localhost:1337/News/' + this.$route.params.id).then(response => { this.topic = response.body; this.comments = response.body['comments']; this.loading = false; }); } }, created() { this.loading = true; this.fetchTopic() }, watch: { '$route': 'fetchTopic' } } </script> <style type="text/css" media="screen"> </style>

Accesing the TopicDetail component give me this error: enter image description here

Can anyone help me figure it out what's wrong? knowing that the name of the Comment component is present and set to 'comment'..

Categories: Software

v-bind in nested component for radio input is breaking

Wed, 2017-07-19 15:56

The problem is I cannot click nested radio button but able to click top level radio buttons.

I have this component imported in parent view:

<app-group-radio-item v-for="groupsNested in groupsDataNested" :key="groupsNested.group_id" :groups="groupsNested" :groupInputtedData="groupInputtedData"> </app-group-radio-item> <script> import AppGroupRadioItem from "./GroupRadioItem"; export default { name: 'addGroup', components: {AppGroupRadioItem}, props: { groupsDataNested: Array, }, data(){ return { groupInputtedData: { group_name: '', group_type_id: '', group_parent_id: '' } } } } </script>

The Nested component that I am importing:

<template> <div class="list-group list-group-flush"> <div class="list-group-item"> <div class="form-group"> <label class="custom-control custom-radio"> <input type="radio" class="custom-control-input" :value="groups.group_id" v-model="groupInputtedData.group_parent_id"> <span class="custom-control-indicator"></span> <span class="custom-control-description">{{groups.group_name}}</span> </label> </div> </div> <div class="collapse nested-items" :id="'collapseExample' + groups.group_id + 'radio'" v-if="hasChildren"> <app-group-radio-item v-for="groupsNested in groups.groups" :key="groupsNested.group_id" :groups="groupsNested" :groupInputtedData="groupInputtedData"> </app-group-radio-item> </div> </div> </template> <script> export default { name: 'appGroupRadioItem', data: function () {}, props: { groups: Object, groupInputtedData: Object } } </script>

Thanks in advance.

Categories: Software

How can I make Vuex 'invisible' in VueJS DevTools

Wed, 2017-07-19 15:46

There is a config option for vuejs to turn off inspection for the components. This is accessed through

Vue.config.devtools = false

When you set that code before initializing Vue, the user (or you) will not be able to inspect the components and you will get the following message vue devtools disabled

I am looking for a similar config for vuex because even with the Vue Js devtools turned off, I can still see the store including mutations and the ability to undo them which is something I don't want.

Is there a way to turn off vuex store inspection?

Categories: Software

Reusable component access child method in parent slot

Wed, 2017-07-19 15:28

Say I have a component Reusable with a method onClick that sets a data prop. I want this component to be reusable, and I want to use slots to override parts.

As I understand the canon, I must pass the onClick method as a scoped property up to parent from reusable:

<div class="reusable"> <h2>Reusable</h2> <slot name="clicker" v-bind:onClick="onClick"> Default stuff <button v-on:click="onClick">Close</button> </slot> <p v-if="clicked">You clicked me</p> </div> <div class="parent"> <h1>Parent</h1> <reusable> <template slot="clicker" scope="reusable"> <button click="reusable.onClick"> Close from parent </button> </template> </reusable> </div>

This might get verbose and noisy if I have a lot of methods, and I wondered: is there a better way, or is this entirely cromulent?

I've looked at using refs, and having methods on the parent call this.$refs.reusable.onClick, as well as specifying dynamic components and swapping them out; both seem counterintuitive.

Categories: Software

Can't running Vuejs dependencies were not found

Wed, 2017-07-19 14:59

why i can't running my Vue script using webpack. I get this error.

ERROR Failed to compile with 11 errors 19.32.28 These dependencies were not found: * @/components/naven in ./src/main.js * @/components/navtab in ./src/main.js * @/components/artikel in ./src/main.js * @/components/navbtm in ./src/main.js * @/components/hero in ./src/main.js * @/components/btmdata in ./src/main.js * @/components/navbtn in ./src/main.js * @/components/foot in ./src/main.js * @/components/social in ./src/main.js * @/components/contenthome in ./src/main.js * @/components/Content-home in ./src/router/index.js To install them, you can run: npm install --save @/components/naven @/components/navtab @/components/artikel @/components/navbtm @/components/hero @/components/btmdata @/components/navbtn @/components/foot @/components/social @/components/contenthome @/components/Content-home > Listening at http://localhost:8080 ppabcd@ppabcd:~/server/vue-test$

I get this result in my browser

Cannot GET /
Categories: Software

Custom directives proceeds component render

Wed, 2017-07-19 14:58

I am using a custom click-outside directive from this post:

Detect click outside element

This is my element:

<div class="datepicker panel panel-default" v-click-outside="close">

The custom directive:

module.exports = { bind(el, binding, vnode) { el.event = (event) => { // Check that click was outside the el and his children. if (!(el === event.target || el.contains(event.target))) { console.log('Clicked outside'); // Call the method provided as the attribute value. vnode.context[binding.expression](event); } }; document.body.addEventListener('click', el.event); }, unbind(el) { document.body.removeEventListener('click', el.event); } };

It works and to my knowledge the bind takes place on render of the element. Because I only want the click event to be registered when my datepicker is in view I wrapped it with a v-if.

The problem is that when I use a button to toggle the display of the v-if on the datepicker, the close method from the directive immediately fires.

It seems that the event within bind takes places before the element is even shown, therefore it closes immediately and nothing is shown at all.

This looks like pretty strange behavior singe the button is responsible for showing the datepicker and I would expect the bind to take place when the datepicker has rendered. Not at the same time or before.

Now it seems to take place even before the element has fully rendered. This causes my display button to cause a v-click-outside event.

What is causing this?

Edit:

Made a Jsfiddle to demonstrate this problem(open console):

https://jsfiddle.net/stephanv/qqjnngdz/2/

Categories: Software

self-defined wxcompent in weex whereas empty view

Wed, 2017-07-19 14:48

MyTabMenu is extends WXCompent and it has Register in application,

public class MyTabMenu extends WXComponent {

public MyTabMenu(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) { super(instance, dom, parent); } @Override protected View initComponentHostView(@NonNull Context context) { View rootView = LayoutInflater.from(context).inflate(R.layout.myview_layout,null); return rootView; } @WXComponentProp(name = "msg") public void setMsg(String msg){ Log.e("cable",msg); }

}

but the result page is empty

Categories: Software

Simple if(falsey) statement not working [on hold]

Wed, 2017-07-19 14:47

I have a statement in code which checks a string like so:

if(str){ //do something here }

Even if my str = "" the code inside the check is being executed. Anyone had this? I have checked in console that str == false returns true so really cannot see why the code would be reached?

Cheers

Editing to add answer

My issue appears to be due to the fact that I was using webpack sourcemap and framework Vue.js. There is a setting in a file webpack.dev.config,

devtool: '#cheap-module-eval-source-map'

If I remove the "cheap-module' then debugging operates as expected.

devtool: '#eval-source-map'
Categories: Software

How to fetch data before mounting the root Vue instance?

Wed, 2017-07-19 14:25

TL;DR: vue-devtools does not work correctly if I wait for async stuff to finish before creating / mounting the root Vue instance

I'm new to Vue.js and I'm developping a back office app where nothing is accessible unless the user is logged. Except for the sign in / up pages of course.

So on page load I do something like this:

// Set up store and router ... router.beforeEach(function (to, from, next) { /* redirect to auth if store.state.auth.isLogged is false */ } // Dispatch an action that send a request to the API to get the connected user // (or null if the user is not logged) store.dispatch('getAuth').then(user) { // Mount the app one the request is done and the mutation for isLogged is done new Vue({ el: '#app', router, store, // ... }); }

And in my index.html I have a pure HTML/CSS loading page that waits for the vue app to mount.

So this works fine, on load, the app check if the user is logged and once this is done, it redirects to the auth pag if needed.

My problem is mainly with vue-devtools, it seems that if the root Vue instance is not mounted on page load, I can't inspect elements from the vue-devtools, but the vuex inspection works.

Am I doing something wrong? Or is it a problem with the devtools ?

Categories: Software

Manage Presentation Data in Vue (Resize Events)?

Wed, 2017-07-19 12:34

I'm working a Vue project, and I'm using Vuex to manage the applications state. I've separated out the view of the app into many small layouts, as Vue components. For example I have a layout for a header and a floating stats panel.

I've written a custom directive for affixing the stats panel. Currently, this works similar to Bootstrap where you set a value, and when the page scrolls beyond that point an affix CSS class gets added to the element. This value is based on the height of the header. As app is responsive, I would rather have this value computed from the header outerHeight property.

Now, I can think of several ways on how to accomplish this, however I'm not sure the proper Vue way to do it.

  1. I could listen for resize events and have the header update it's height in the Vuex store. However, it seems poor practice to have the store manage presentation data.
  2. I could pass the id of the header to the affix directive, and use getElementById to check the height. But this is bypassing Vue completely.
  3. I could add a method to the header to return its' height, and have the parent component that holds both the header and stats panel use that to update the affix value. This however, gets messy if header and stats don't share the same parent.

Are there any other options? What would be best practice? Thanks!

Categories: Software

Passing ref's content from a child to another VueJS child component

Wed, 2017-07-19 12:28

I'm learning VueJS and I got a little confused on the ref, $refs lecture. I tried to understand it from vue's documentation, but I didn't get what I want to know.

If for example I have this component:

<user-item ref="details"></user-item>

and I get the data from this component using

this.$refs.details

to use that data in the User parent component, because this user-item is a child for User component.

<div id="User"> <user-item ref="details"></user-item> </div>

In the same time I have another component called, let's say Permissions that's child too, for User component:

<div id="User"> <user-item ref="details"></user-item> <permissions></permissions> </div>

In this Permissions component I need the same this.$refs.details, but from what I test, like an experiment, doesn't work.

This is just a simple example.

Can someone please tell me how can I do it?

Categories: Software

testcafe injecting many specs to one test

Wed, 2017-07-19 12:15

I have specified files: model and spec for every page like main page & register page. Every spec file has their own fixture and tests checking one mage (for example: register page).

The question is how can I include many spec files into one big checking every page.

Categories: Software

Vue.js 2 with laravel Role Based Auth Admin Panel

Wed, 2017-07-19 12:00

I need suggestion how can i make a role based admin panel using vue.js 2 and laravel 5. I need routes in vue.js routes file and in laravel only one entry point for all router.

Ex :

Laravel route looks like :

/* Dashboard Index */ Route::group(['prefix' => 'dashboard', 'middleware' => ['auth', 'admin']], function () { Route::get('{path?}', 'HomeController@dashboard')->where('path', '[\/\w\.-]*'); });

Routes.js looks like :

export default [ { path: '/dashboard', component: Dashboard, beforeEnter: requireAuth, children: [ { path: '/', redirect: '/dashboard/home' }, { path: 'home', component: require('dashboard/Home.vue') }, { path: '*', redirect: '/dashboard' } ] } ]
Categories: Software

Vuex getter will not update

Wed, 2017-07-19 11:25

I am using a datepicker to set a moment.js date which is being set in my Vuex store:

Store state:

const state = { arrival: '', departure: '' }

Getters:

const getters = { arrival: state => state.arrival, departure: state => state.departure, prettyArrival: (state) => { if (state.arrival instanceof moment) { return state.arrival.format(state.prettyFormat); } return ''; } }

My vuex store is properly updating the arrival state(which is a moment.js object) because I can clearly see the devtools showing the updates and the original state changing.

The prettyArrival is not updating at all though. It is only being set once when the arrival changes from an empty string to a moment.js object.

My arrival getter shows in the devtools like this:

arrival:"2017-07-21T09:15:53.770Z"

When I log it I get the moment.js object though with seems to contain reactiveGetters and reactiveSetters so the reactivity seems in place.

Is there something wrong with how I set up my getter or is something else wrong here?

Any tips are welcome, if you need more info let me know.

Categories: Software

How can I use selectize in an input form in Vue

Wed, 2017-07-19 11:22

Suppose I have an input field: <input type="text" placeholder="Select Teams" /> and I should be able to select Support by clicking the input field.

enter image description here

and then

enter image description here

I learned that this is possible using selectize. How should I be able to incorporate it as a vue directive?

Categories: Software

vue js navigate to url with question mark

Wed, 2017-07-19 11:07

my Vue js project login template click button it redirects to like this

http://localhost:8080/#/login to http://localhost:8080/?#/login

how to solve it?

Categories: Software

Vue.js Avoriaz unit test produces translation warnings when vue-i18n is used

Wed, 2017-07-19 10:21
Summary

I am using vue-i18n for i18n and Avoriaz for unit testing my Vue.js components. I get many warnings because of not translated strings, which I can't fix. How can I get rid of these warnings?

Warning example

'[vue-i18n] Cannot translate the value of keypath 'description.first'. Use the value of keypath as default.'

Test setup import Vue from 'vue' import Vuex from 'vuex' import { mount } from 'avoriaz' import sinon from 'sinon' import VueResource from 'vue-resource' import BootstrapVue from 'bootstrap-vue' import VueI18n from 'vue-i18n' import store from './../../../state/index' import Register from '@/components/Register' Vue.use(BootstrapVue) Vue.use(VueResource) Vue.use(VueI18n) describe('Register', () => { it('should accept inputs', () => { store.locale = 'en' const wrapper = mount(Register, { store }) let name = 'Hans' let password = '123' let nameInput = wrapper.find('input')[0] let passwordInput = wrapper.find('input')[1] nameInput.element.value = name passwordInput.element.value = password nameInput.trigger('input') passwordInput.trigger('input') expect(wrapper.vm.$store.state.user.name).to.equal(name) expect(wrapper.vm.$store.state.user.password).to.equal(password) }) }) Tested component <template> <div class="row justify-content-md-center"> <div class="col-6"> <b-form-fieldset :description="$t('description.first')" :label="$t('label.first')" :label-size="1"> <b-form-input v-model="name"></b-form-input> </b-form-fieldset> <b-form-fieldset :description="$t('description.second')" :label="$t('label.second')" :label-size="1"> <b-form-input v-model="password" type="password"></b-form-input> </b-form-fieldset> <b-button variant="outline-success" size="sm" @click="create">{{ $t('button.first') }}</b-button> </div> </div> </template> <script> export default { i18n: { messages: { en: { 'description.first': 'Enter a name', 'label.first': 'Name *', 'description.second': 'Enter a password', 'label.second': 'Password *', 'button.first': 'Create' }, de: { 'description.first': 'Gebe einen Namen ein', 'label.first': 'Name *', 'description.second': 'Gebe ein Passwort ein', 'label.second': 'Passwort *', 'figcaption.first': 'Du kannst einen dieser Nutzer wählen, um dich einzuloggen.', 'button.first': 'Erstellen' } } }, computed: { user: { get () { return this.$store.state.user } }, name: { get () { return this.$store.state.user.name }, /** * @param name */ set (name) { this.$store.commit('SET_USER_NAME', name) } }, password: { get () { return this.$store.state.user.password }, /** * @param password */ set (password) { this.$store.commit('SET_USER_PASSWORD', password) } } }, methods: { create () { this.$store.dispatch('saveUser', this.user) } } } </script>
Categories: Software

Pages