Vuejs

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

Is it possible to get client's ip address in vuejs [duplicate]

Tue, 2017-09-12 14:48

This question already has an answer here:

I am trying to store get client's ip address in vuejs. Any one please tell me a good way of doing that.

Categories: Software

Import CSS file with Fonts in VueJS

Tue, 2017-09-12 14:43

I have a Vue application and I want use a line-awesome font. But in my App.vue that is my component I import css file fonts in this way:

@import 'assets/fonts/line-awesome/css/line-awesome.min.css';

My problem is that no errors are shown, but my fonts are not loaded in my app.

In that css file, it contains this font face:

@font-face { font-family: "LineAwesome"; src: url("../fonts/line-awesome.eot?v=1.1."); src: url("../fonts/line-awesome.eot??v=1.1.#iefix") format("embedded-opentype"), url("../fonts/line-awesome.woff2?v=1.1.") format("woff2"), url("../fonts/line-awesome.woff?v=1.1.") format("woff"), url("../fonts/line-awesome.ttf?v=1.1.") format("truetype"), url("../fonts/line-awesome.svg?v=1.1.#fa") format("svg"); font-weight: normal; font-style: normal; }

Now I don't know if my problem is because my path is wrong setted or I need a additional configuration in my app.

Some idea about how I can fix it?

Categories: Software

Is it possible to use browser->drag() from dusk with Vuedraggable?

Tue, 2017-09-12 14:42

We are using VueDraggable (and Vue) in our front-end and we are testing our front-end with Dusk.

I am currently trying to use $browser->drag('selector', 'selector') from dusk to drag objects from one list to the other, but I don't see anything happening during the test (although it might be the action is not visible) nor is the right result shown, the object does not end up in the indicated list.

I was wondering if anybody made a working example already of using $browser->drag() combined with Vue.draggable? I am asking since I don't know if I am trying the impossible or not.

Categories: Software

How to get value of textarea field in HTML using Traits in GrapesJS

Tue, 2017-09-12 14:36

I follow this example for making new Traits type, it's completely working. Now I want this specific Textarea value show in HTML in GrapesJS.

editor.TraitManager.addType('textarea', { events:{ 'keyup': 'onChange', // trigger parent onChange method on keyup }, /** * Returns the input element * @return {HTMLElement} */ getInputEl: function() { var selectedModel = this.target; var input = document.createElement('textarea'); input.value = selectedModel.get('textarea'); return input; }, /** * Triggered when the value of the model is changed */ onChange: function () { this.target.set('textarea', this.model.get('value')); } }); { type: 'textarea', name: 'textarea' }

Here I show this textarea Example in GrapesJS.

Categories: Software

How to catch Jquery event from vue.js

Tue, 2017-09-12 14:24

Scenario: I have an iframe (which is hosted in the same domain, but purely use Jquery only) and it is already coded to trigger some events with parameters. And I have to catch those events with parameters in the parent vue.js application.

iframe:

$('*').mouseover(function (event) { var event = jQuery.Event( "mouseover-highlight" ); event.top = $(this).offset().top; event.left = $(this).offset().left; parent.$('body').trigger(event); });

vue.js

Catch this event somehow from the vue.js and set a div's css styles accordingly (Set the 'absolute' position). I have done it using vue.js before v2 comes by using Jquery inside the vue.js, But I've seen in the docs that vue.js isn't able to catch native events anymore. Any solution ?

Categories: Software

Passing default data to Vue form component

Tue, 2017-09-12 13:48

Here is a simple Vue 2.0 form component. It consists of a number input and a button, e.g.:

enter image description here

Note that the value of the input is tied to the component's data using v-model. buttonText is passed in as a prop.

What's the best way to pass a default value into the form, so that it initially renders with a value other than 10?

  • Using props doesn't seem to be the right way to do it because then v-model no longer works properly.
  • However, data can't be passed in the way props can, as far as I can tell from Vue documentation.

.

<template> <form v-on:submit.prevent="onSubmit"> <input v-model="amount" type="number" min="1" max="20"></input> <button type="submit">{{ buttonText }}</button> </form> </template> <script> export default { props: [ 'buttonText' ], data: function() { return { amount: 10 } }, methods: { onSubmit: function() { this.$emit("submit", parseInt(this.amount) ); } } } </script>
Categories: Software

How to pass a string containing slash ('/') as parameter to a route in vue.js

Tue, 2017-09-12 13:44

I am using vue router and I have a route

{ path: '/my-route/:param?', component: MyComponent }

I have the link to my route as

<router-link :to="'/my-route/'+myParam">Link text</router-link>

if myParam is a string containing '/' like 'abc/def', it navigates to the link /my-route/abc/def which doesn't exists. How to solve this?

Categories: Software

Access to vue properties

Tue, 2017-09-12 13:28

In my authority system I store secret token in Vue fields and get it from localStorage in created event:

const app = new Vue({ router: router, data: { token: '', user: null, }, created: function () { var token = localStorage.getItem('token'); if (token) { this.token = token; } ...

Then I'm trying to fetch token in beforeRouteEnter method of compomnent:

beforeRouteEnter: function (to, from, next) { var id = to.params.id; console.log(router.app.$root.token); },

But the field is empty, however it defined later. How to correct structure of my application to send api requests with token?

Categories: Software

nuxt build --spa vs nuxt generate

Tue, 2017-09-12 13:17

What is the difference between

nuxt build --spa

vs

nuxt generate

I am trying to compile three different variations:

1. regular nuxt with ssr 2. prerendered spa 3. spa without prerendering

I am struggling to find the appropriate commands for it

Categories: Software

List rendering key

Tue, 2017-09-12 12:39

The documentation states that list rendering using v-for without key is

only suitable when your list render output does not rely on child component state or temporary DOM state (e.g. form input values).

Will the following code cause problems if itemArray is modifed using splice/push/pop?

<div v-for="item in itemArray"> ... <textarea v-bind:value="item.value" v-on:input="item.value = $event.target.value"> </textarea> ... </div>

If not, what is an example where there would be a problem?

Categories: Software

Difference between scoped CSS and "scope" by adding a parent class

Tue, 2017-09-12 12:24

When building an app using vue, vue-loader and the official boilerplate I noticed scoped css is used to limit the CSS to the current component. I don't see the point in this. I have always "scoped" css by defining it inside a wrapper class when I have felt the need for it.

For example in SASS:

.some-module { h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } }

So what do i gain from using scoped CSS instead? Or is it merely just another method to achieve the same thing?

Categories: Software

how to hot reload component with ts and vue-property-decorator

Tue, 2017-09-12 12:07

Every code I changed on the .ts file will trigger the browser refresh, and I do not want it work this way. I have tried many solutions like "vue-ts-loader", "vue-hot-reload-api",..., but I have not found a good one. How you guys fixed this issue?

Categories: Software

Update the View of a web application from a DynamoDB update

Tue, 2017-09-12 12:02

Just wondering if anyone has done something like this. I'll add some context.

So there are two applications. A mobile app and a Vue.js web application which acts as a static DevOps board. The mobile app makes an updated to the DynamoDB table which the DevOps board should be listening too and updated the view. Like a live reload. I want to try and stay away from a timer of sorts to make a call to the DB again and pull down the objects.

I know Firebase acts like a live reload of data but I want to try and just use AWS unless someone has done something like this before.

Thanks

Categories: Software

Can't load static files inside Vue.js component

Tue, 2017-09-12 10:47

I have component Login.vue and inside its template I paste

<img src="logo.png">

The catalog structure is the same as here: https://vuejs-templates.github.io/webpack/static.html

I got static folder inside src folder.

I try many diffrent combinations like

<img src="src/assets/logo.png"> <img src="assets/logo.png">

When I try to write with a dot prefix (absolute path)

<img src="./src/assets/logo.png">

I got and error from babel compiler: Module not found: Error: Can't resolve './logo.png'

Categories: Software

Getting Google Maps to work with Vue.js

Tue, 2017-09-12 10:26

I'm trying to get Google maps working with Vue.js.

This is the html I am using:

<strong>Map</strong><br> <div id="map-container"> <div id='location-map'></div> </div> ... <script src="https://maps.googleapis.com/maps/api/js?key=MYKEY"></script>

and my Vue binding:

if(document.getElementById("map-container")) { const mapVue = new Vue({ el: '#map-container', data: { defaultLatLng: {lat: 37.5665, lng: 126.9780} }, mounted: function() { var map = new google.maps.Map(document.getElementById('location-map'), { zoom: 15, center: this.defaultLatLng, scrollwheel: false, disableDoubleClickZoom: true, panControl: false, streetViewControl: false, draggable: false }); var marker = new google.maps.Marker({ position: this.defaultLatLng, map: map }); } }) }

But the map is not displaying. Am I doing something incorrectly here?

Thanks in advance!

Categories: Software

Axios and vue-resource put method doesn't work

Tue, 2017-09-12 10:04

I have on front vuejs and on backend java. In one component I bring the users from the database.

Users.vue

getUsers() { this.$http.get("/user") .then((response) => { this.users = response.data.users; }) }

Still here I use v-for to bring all users in another component User.vue.

<app-user v-for="user in users" :user="user" :key="user.index"></app-user>

In user component I have a router link that takes me to another page where I can edit the username.

User.vue

<p class="user-name">{{user.firstName}}</p> <router-link :to="'/users/edit-user/'+user.id"> <a ><i class="ti-pencil-alt" aria-hidden="true"></i></a> </router-link>

EditUser.vue

<template> <input type="text" :value="user.firstName" v-model="userInfo.firstName"> </template> <script> export default { data() { return { user: {}, userInfo: { firstName: '', } } }, created() { this.getUsers(); }, methods: { getUsers() { this.$http.get("/user/" + this.$route.params.id) .then((response) => { this.user = response.data; }) }, updateUser() { axios.put('/user', this.userInfo, {'headers':{'X-AUTH-TOKEN':localStorage.token}}, {'headers':{'Content-Type': 'application/json'}}) .then((response) => { console.log("Success! You edited the user"); }) .catch((response) => { console.log('Error in edit'); }) } }, } </script>

I started learning vuejs a month ago and still have to learn :).

In the input I use :value="user.firstName" to bring the value for firstName that already exists. I try to use v-model="userInfo.firstName" to get new value for userName, but when I put this, the value, that existed already, disappears from the input.

To save data with post works fine but only with axios. I don't know why post doesn't work with vue-resource. So I tried put with axios too, but what I edit when I press save button, on EditUser.vue, my request doesn't go to server.

I say this because I saw that in the backend I don't get any error, nothing, but if I use post or get I can get or save users.

What do I do wrong in my code that I don't edit the user?

Categories: Software

Vue removing wrong HTML node in dynamic list of components

Tue, 2017-09-12 09:59

I'm experimenting with Vue.JS and composing components together with dynamically.

There's a strange issue where although it seems to be updating the data correctly, if I remove one of the boxes with the call to splice() it always removes the last item in the rendered HTML.

Here's an example fiddle. I'm testing in Chrome.

https://jsfiddle.net/afz6jjn0/

Just for posterity, here's the Vue component code:

Vue.component('content-longtext', { template: '#content-longtext', props: { model: { type: String, required: true }, update: { type: Function, required: true } }, data() { return { inputData: this.model } }, methods: { updateContent(event) { this.update(event.target.value) } }, }) Vue.component('content-image', { template: '#content-image', }) Vue.component('content-list', { template: '#content-list-template', props: { remove: { type: Function, required: true }, update: { type: Function, required: true }, views: { type: Array, required: true } }, methods: { removeContent(index) { this.remove(index) }, updateContent(index) { return (content) => this.update(index, content) }, }, }) Vue.component('content-editor', { template: '#content-editor', data() { return { views: [ {type: 'content-longtext', model: 'test1'}, {type: 'content-longtext', model: 'test2'}, {type: 'content-longtext', model: 'test3'}, {type: 'content-longtext', model: 'test4'}, {type: 'content-longtext', model: 'test5'}, ], } }, methods: { newContentBlock(type) { this.views.push({type: 'content-longtext', model: ''}) }, updateContentBlock(index, model) { this.views[index].model = model }, removeContentBlock(index) { this.views.splice(index, 1) }, }, }) let app = new Vue({ el: '#app' })
Categories: Software

Vue.js unit tests axios-mock-adapter never called

Tue, 2017-09-12 08:57

testing the following spec with axios-mock-adapter

actions.spec.js

import actions from '@/vuex/actions' import * as types from '@/vuex/mutation_types' import axios from 'axios' import MockAdapter from 'axios-mock-adapter' describe('actions.js', () => { var mockAdapter, store, lists beforeEach(() => { // mock shopping lists lists = [{ id: '1', title: 'Groceries' }, { id: '2', title: 'Clothes' }] // mock store commit and dispatch methods store = { commit: (method, data) => {}, dispatch: () => { return Promise.resolve() // static method }, state: { shoppinglists: lists } } sinon.stub(store, 'commit') mockAdapter = new MockAdapter(axios) mockAdapter.onGet('http://localhost:3000/shoppinglists').reply(() => { console.log('SERVER ON GET: ') return new Promise((resolve, reject) => { setTimeout(() => { if (Math.random() > 0.1) { console.log('lists: ', lists) resolve([ 200, lists ]) } else { // reject() reason will be passed as-is. // Use HTTP error status code to simulate server failure. resolve([ 500, { success: false } ]) } }, 1000) }) }) }) afterEach(() => { // restore stubs and mock server store.commit.restore() mockAdapter.restore() }) describe('populateShoppingLists', () => { it('should call commit method with POPULATE_SHOPPING_LIST string parameter', () => { return actions.populateShoppingLists(store).then(() => { expect(store.commit).to.have.been.calledWith(types.POPULATE_SHOPPING_LISTS, lists) }) }) }) })

as I can see in the following debug log, mockAdapter.onGet() is never called ( so not returning the spec lists), instead the axios instance is called and returning the db content...

what's wrong in my code ? thanks for feedback

console

... LOG LOG: 'ACTION POPULATE: ' LOG LOG: 'API FETCH SHOPPINGLISTS' LOG LOG: 'API RETURNED: ', [Object{title: 'TESTS', items: [..., ...], id: 3}, Object{title: 'LAST TEST', items: [..., ...], id: 4}] 1) should call commit method with POPULATE_SHOPPING_LIST string parameter actions.js populateShoppingLists AssertionError: expected commit to have been called with arguments POPULATE_SHOPPING_LISTS, [{ id: "1", title: "Groceries" }, { id: "2", title: "Clothes" }] POPULATE_SHOPPING_LISTS [{ id: 3, items: [{ checked: false, text: "Bananas" }, { checked: true, text: "Apples" }], title: "TESTS" }, { id: 4, items: [{ checked: true, text: "boots" }, { checked: true, text: "pants" }], title: "LAST TEST" }] [{ id: "1", title: "Groceries" }, { id: "2", title: "Clothes" }] at webpack:///test/unit/specs/vuex/actions.spec.js:75:42 <- index.js:17581:43 at <anonymous>

actions.js

import * as types from './mutation_types' import api from '../api' import getters from './getters' export default { populateShoppingLists: ({ commit }) => { console.log('ACTION POPULATE: ') return api.fetchShoppingLists() .then(response => { console.log('API RETURNED: ', response.data) commit(types.POPULATE_SHOPPING_LISTS, response.data) }) .catch(e => { console.log('POPULATE ERROR : ', e) }) } }

api/index.js

import { HTTP } from './http-common' export default { fetchShoppingLists: () => { console.log('API FETCH SHOPPINGLISTS') return HTTP.get('shoppinglists') } }

api/http-common.js

import axios from 'axios' export const HTTP = axios.create({ baseURL: 'http://localhost:3000/' })
Categories: Software

Vue.js component with dynamic template (e.g. eventhandler)

Tue, 2017-09-12 08:41

lets say I made a compontent called test and inserted this into my html like so:

<test :data="foo"></test>

How can I achieve that the on-click attribute value changes into the property value 'data'?

Vue.component('test', { props: ['data'], template: '<div v-on:click="type={{data}}"></div>' });

Just to outline my expectations - this is what I am looking for:

<test :data="bar"></test>

renders to

<div v-on:click="type='bar'"></div

BTW: Thanks to everyone participates here in SO :)

Categories: Software

Eventsource problems with webpack and vuejs

Tue, 2017-09-12 06:05

I'm making my own blog using express and vuejs. In login.vue, I found that websites redirected to localhost:8080/?#/login after i pushed 'submit button' in Chrome. (It works perfect in Firefox) so I had to log in 'twice' in order to sign in.

after post 'request', following errors occur before (response) => { ... }

EventSource failed loading : GET "localhost:8080/__webpack_hmr" XHR failed loading: POST "localhost:8080/login" Navigated to localhost:8080/?

but funny thing is after redirected to /?#/login, it worked successful. I just want to know about why this errors occured. I guess it might be Webpack error but I don't know how to fix it.

<template> <div id="app"> <div class="alert alert-primary" role="alert" v-if="showAlert"> <h4 class="alert-heading">{{alertStatus ? "Success":"Warning"}}</h4> <p>{{alertMsg}}</p> </div> <div v-if="!isLogged"> <form> <ul class="nav nav-pills justify-content-center"> <li class="nav-item"> <a class="nav-link" v-bind:class="{ active: logMode }" v-on:click="changeMode">Sign In</a> </li> <li class="nav-item"> <a class="nav-link" v-bind:class="{ active: regMode }" v-on:click="changeMode">Sign Up</a> </li> </ul> <div class="form-group" key="email"> <input type="email" class="form-control" id="email" v-model="email" aria-describedby="emailHelp" placeholder="Enter email"> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> </div> <div class="form-group" v-if="regMode" key="email2"> <input type="email" class="form-control" id="emailConfirm" v-model="emailConfirm" placeholder="Enter email again"> </div> <div class="form-group" v-if="regMode" key="nick"> <input type="text" class="form-control" id="nickname" v-model="nick" placeholder="Enter nickname"> </div> <div class="form-group" key="password"> <input type="password" class="form-control" id="password" v-model="password" placeholder="Password"> </div> <div class="form-check" key="check"> <label class="form-check-label"> <input type="checkbox" class="form-check-input"> Check me out </label> </div> <button v-on:click="submit" class="btn btn-primary">{{isMode}}</button> </form> </div> <div v-else> <span> Already Signed in. </span> </div> </div> </template> <script> export default { name: 'login', computed: { logMode: function () { if (this.isMode === 'Login') return true else return false }, regMode: function () { if (this.isMode === 'Register') return true else return false } }, methods: { changeMode: function () { if (this.isMode === 'Login') this.isMode = 'Register' else if (this.isMode === 'Register') this.isMode = 'Login' }, submit: function () { console.log('submit on') if (this.isMode === 'Register') { this.$http.post('/register', { email: this.email, nick: this.nick, password: this.password }) .then((response) => { console.log('get response!') }) .catch(function (error) { console.log(error) }) } else { if (this.email) { console.log('email exist') this.$http.post('/login', { email: this.email, password: this.password }) .then((response) => { console.log('hello response!', response.data) var token = response.data.token if (token) { console.log('param test: ', this.email, response.data.nick, token) this.isLogged = true this.token = token } }) .catch(function (error) { console.log(error) }) } } } }, data () { return { email: '', emailConfirm: '', nick: '', password: '', showAlert: false, alertMsg: '', alertStatus: false, isLogged: false, isMode: 'Login', token: '' } } } </script> <style> #login{ margin: 50px; } .nav{ width: 320px; padding: 10px; } .inputs-move { transition: all 1s; } .inputs-item { display: inline-block; } .inputs-enter-active, .inputs-leave-active { transition: all 1s; } .inputs-enter, .inputs-leave-to { opacity: 0; transform: translateY(-30px); } </style> also source codes are in https://github.com/Azurepeal/kajarga

Categories: Software

Pages