Software

How to show specific field on click button of a loop vue js

Vuejs - Wed, 2017-07-26 11:28

I have a posts loop where each post has a comment box.Initially all comment box are hidden and when someone clicks on 'comments' button it should show the comment field for this user. I am having trouble to show specific comment box associated with the specific post. my code is as follows -

<div class="post-section" v-for="(post,index) in posts"> <div class="media-content">{{post.body}}</div> <button @click="getComments(post, index)" class="btn btn-link"><i class="fa fa-comments-o"></i>{{ post.total_comments }} Comments</button> <comment-input :postId="post.id"></comment-input> </div> <script> export default { data() { return { posts: [], } }, created() { Post.all(posts => this.posts = posts); }, methods: { getComments(post, index){ axios.post('getcomments', {id: post.id}) .then(response => { this.$set(this.posts, index, Object.assign({}, post, { comments: response.data })); }); }, } } </script>

When getComments(post, index) method executes i want to make the next comment-input only. Any help??

thanks in advance.

Categories: Software

Failed to download repo vuejs-templates/webpack: EACCES: permission denied, mkdir '/.vue-templates'

Vuejs - Wed, 2017-07-26 11:23

I'm trying to learn Docker. I installed Docker ToolBox on Windows 10 (I have Home Edition, so I can't use regular Docker installation because that Windows version doesn't have Hyper-v).

Next, I tried this container from Docker Hub:

docker pull ebiven/vue-cli

I added new alias as was written on container page (I changed name to vuejs because I have vue installed locally):

alias vuejs='docker run -it --rm -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" ebiven/vue-cli vue'

And then in the console I wrote:

vuejs init webpack .

I got an error message:

vue-cli · Failed to download repo vuejs-templates/webpack: EACCES: permission denied, mkdir '/.vue-templates'

How to fix this?

Categories: Software

vueify+node: compile separate .vue files

Vuejs - Wed, 2017-07-26 11:10

It is possible to setup vueify this way, so it compiles single .vue files to corresponding .js files?

For example.

Input: my-component.vue

<template> <div>{{ message }}</div> </template> <script> module.exports = { data() { return { message: 'Hello World', }; }, }; </script>

Output: my-component.js

Vue.component('my-component', { template: '<div>{{ message }}</div>', data() { return { message: 'Hello World', }; }, });
Categories: Software

Unable to get datepicker to work with VueJS2

Vuejs - Wed, 2017-07-26 10:43

I am trying to use jquery-ui with VueJS 2 so i can use functions such as datepicker, sortable and slider. However, i am faced with an error:

TypeError: $(...).datepicker is not a function

Here's what i've done to try get this working, in my app.js file i have loaded JQuery and JQuery UI before I require Vue:

window.$ = window.jQuery = require('jquery'); window.$ = $.extend(require('jquery-ui'));

I have created my component slider and here is the content:

Vue.component('datepicker', require('./components/Datepicker.vue'));

Here is the component itself

<template> <div class="datepicker"></div> </div> </template> <script> export default { data() { return { }; }, mounted() { $(this.el).datepicker(); } } </script>

How can I get this to work?

Categories: Software

DragEnd event not fired for files

Vuejs - Wed, 2017-07-26 10:40

My template

<div class="upload-component" @dragend="log('end')" @dragenter="dragEntered" @drop.prevent @dragover.prevent> <div class="zone" @drop="dropped"> </div> <p draggable="true">drag me</p> </div>

My js

export default { name: 'UploadComponent', methods: { log(str){ console.log(str) }, dragEntered(e){ // change some styles }, dropped(e){ console.log(e.dataTransfer.files) } } }

The problem: If I drag the P element and drop it or hit escape it will log "end". If I come with a file from my desktop and put it back on desktop or hit escape or drop it, the dragend event wont fire and it wont log anything

Categories: Software

Webpack UglifyJS running into unexpected token

Vuejs - Wed, 2017-07-26 10:31

I am trying to set up a development boilerplate which can also easily push a Vue.js project to NPM.

I am running into a problem with my webpack.prod.js file, the error is:

ERROR in build.js from UglifyJs Unexpected token: operator (>)

The code to uglify is:

// minify with dead-code elimination new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })

This is my project and the exact file where it seems to go wrong:

https://github.com/stephan-v/vue-inline-svg/blob/master/webpack/webpack.prod.js

The project uses Babel to transpile to ES6 and Webpack to compile to UMD format when I run npm run production. This command uses the webpack.prod.js configuration.

I am probably not seeing something that could be fixed easily but I have no clue what is going wrong here.

Categories: Software

conditional binding in vue js

Vuejs - Wed, 2017-07-26 09:30

stores data using ajax

data: datas: new dataBinder() methods: dataBind: (event)-> parent = this current = event.currentTarget $.ajax url: $(current).attr("data-action") type: $(current).attr("data-method") dataType: "json" contentType: "application/json" headers: 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') success: (msg)-> parent.datas.store(msg) error: (msg)-> console.log(msg.responseJSON)

class of databinder

class dataBinder constructor: ()-> @datas = {} get: (field)-> if (@datas[field]) @datas[field] else @datas = null store: (datas)-> @datas = datas clear: ()-> @datas = {}

hello im having a trouble in vue js i want to bind my object in my input if the object is not null using

v-bind:value="datas.get('code')"

this code is working however...everytime there's an event happening, my inputs value sets to null (or clearing my inputs)

is there a way to make vue bind properties only if my object is not null?

Categories: Software

Vue i18n regex missing transaltions

Vuejs - Wed, 2017-07-26 09:17

have a small question, I have used i18n and it is great but is there a way to see missing translations before starting the app and walking trough components

Examples here https://github.com/kazupon/vue-i18n/pull/177 Here it is ok , but can I see all missing translation without having to traverse the app manually. I mean when I just start app I want to see all missing translation not only when I run specific component. I have script to search trough translations but I cannot find regex for {{ $i18n.t("save me") }} to search it.

Thanx in advance

Categories: Software

Single page mobile website using VUE JS

Vuejs - Wed, 2017-07-26 07:31

I’m planning to develop the mobile website using VUE JS. The site is like a Social web site. Is Developing as Single Page Application is a good idea?

Categories: Software

Introducing js framework into legacy asp.net mvc

Vuejs - Wed, 2017-07-26 05:09

I recently stepped into a large project written on ASP.NET MVC4, generally server generated pages fit well, but some places require rich client side logic. Currently it is done through direct DOM (jQuery) manipulation, that looks VERY messy and results lots of bugs due to lack testing capabilities. As far as I can see, the only things that require are: validation, hide/show controls based on user input and results of ajax calls. Also, I see quite a resistance from a team, people just never have seen well working client side apps and don't understand benefits.

I was working with Angular, but not sure we need a whole framework.

Could community recommend technique/framework that solve my problem in fast and elegant way?

Thanks

Categories: Software

Laravel Setting form value="old('input')" with Vue JS 2

Vuejs - Wed, 2017-07-26 04:09

I have a simple form with a calculator for the amount being charger including shipping and tax. If the form is submitted and comes back with errors, how do I display the old input into the value field of the form with Vue JS? The instance values are coming back correct however they are not displayed in the form.

<div class="form-group"> <label for="totalAmount">Total Amount</label> <div class="input-group"> <div class="input-group-addon">$</div> <input type="totalAmount" class="form-control" id="totalAmount" name="totalAmount" value="{{old('totalAmount')}}" v-model="totalAmount" v-on:change="getTotal" placeholder="0.00" required> </div> </div> <div class="form-group"> <label for="shipAmount">Shipping Amount</label> <div class="input-group"> <div class="input-group-addon">$</div> <input type="shipAmount" class="form-control" id="shipAmount" name="shipAmount" value="{{ old('shipAmount') }}" v-model="shipAmount" v-on:change="getTotal" placeholder="0.00"> </div> </div> <div class="form-group"> <label for="taxRate">Tax Rate</label> <div class="input-group"> <div class="input-group-addon">%</div> <input type="taxRate" class="form-control" id="taxRate" name="taxRate" value="{{ old('taxRate') }}" v-model="taxRate" v-on:change="getTotal" placeholder="0.00"> </div> </div> <div class="widget-body text-center"> <h4 class="m-b-md">Total Amount $ @{{ combinedAmount }}</h4> </div>

JS File:

new Vue({ el: '#app-content', data: { billSameAsShip: '', isHidden: 'true', totalAmount: '', shipAmount: '', taxRate: '', combinedAmount: '' }, computed: { totalAmount2: function () { return this.totalAmount = {{ old('totalAmount') ?? 0 }}; }, shipAmount2: function () { return this.shipAmount = {{ ( old('shipAmount') ?? 0 ) }}; }, taxRate2: function () { return this.taxRate = {{ ( old('taxRate') ?? 0 ) }}; } }, beforeUpdate() { this.getTotal() this.totalAmount = this.totalAmount2; }, methods: { onChange: function() { if(this.billSameAsShip == 'false'){ this.isHidden = !this.isHidden; } else { this.isHidden = Boolean('true'); } }, checkNaN: function() { if(isNaN(parseFloat(this.totalAmount))){ this.totalAmount = 0 } if(isNaN(parseFloat(this.shipAmount))){ this.shipAmount = 0 } if(isNaN(parseFloat(this.taxRate))){ this.taxRate = 0 } }, getTotal: function() { this.checkNaN(); this.combinedAmount = (parseFloat(this.totalAmount) + parseFloat(this.shipAmount)) * (1 + (parseFloat(this.taxRate /100))); } } }) </script>
Categories: Software

Sending axios get request with authorization header

Vuejs - Wed, 2017-07-26 04:07

I have tried to send axios get request using vue.js and it worked just fine when there was no need to send headers. However, when it was required to send an authorization jwt, i was getting CORS error: "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." I don't know why is this problem occurring since there is Access-Control-Allow-Origin: '*' header in the response. My code is the following:

axios.get(url, { headers: { 'Authorization': 'Bearer TOKEN' } }) .then(function (response) { console.log(response.data) })

The weirdest thing is when I use querystring.stringify or JSON.stringify on the header, I don't get the error 403(forbidden), but just an error 401 - Unauthorized. I tried with variable and with the token itself and it didn't work.

I tried to send a post request in order to get a web token with required data - username an password and it worked. I was able to get the token.

I made a whole bunch of research the last two days on this and I found different kind of request structure and configs which I tried all of them, but none were efficient. Is there a way to check if the request is being send with the header? Is something else the problem? If someone can help, I would appreciate. Thanks.

Categories: Software

Check logged user in firebase with Nuxt.js middleware

Vuejs - Wed, 2017-07-26 01:52

I've built some middleware for my Nuxt app.

import api from '~/api/Api.js' export default function ({router, store}) { return api.auth().onAuthStateChanged(function (user) { store.state.user = user if (user) { } else { } }) }

Now, how to actually get access to the user object? When i'm doing this from normal component it's working correctly. Passing to store simple string also works, but any other action no, is there need of some kind of promise? Thx for help.

Categories: Software

Regex for Vue i18n

Vuejs - Wed, 2017-07-26 00:50

I have a simple question, Im looking a way to find missing translations in my Vue app,so How can I make regex to match this expression accross my app. So I need a regex to match this: {{$t('somerandomvalue')}}

Categories: Software

vue draggable almost works

Vuejs - Wed, 2017-07-26 00:07

I am using vue draggable

https://github.com/SortableJS/Vue.Draggable

In My example I am trying to dragg it by specific class

<draggable :list="list" class="dragArea" :options="{draggable:'.dragg-me'}"> <div class="draggable" v-for="element in list"> <div class="dragg-me">dragg me</div> <div class="element"> {{element.name}} </div> </div> </draggable>

Here is the full example: https://jsfiddle.net/v5cff2vw/3/

I need to be able to drag by div that I set to 'dragg-me' class but that is not working, nothing happens when I do that. If I omit draggable option or if I set it to

draggable:'.draggable'

then ofcourse it works again.

Is it possible to get it working the way I would like to?

Categories: Software

Vue js with cometd

Vuejs - Tue, 2017-07-25 23:58

Has anyone tried implementing vue js with cometd ? Do we have to use jquery version of cometd or is there any specific cometd version for vue js like angular js ?

Thanks for your help in advance

Categories: Software

Pass data object from parent to child component

Vuejs - Tue, 2017-07-25 23:42

I'm making a list of tools.

I'm trying to pass the full tool data object from the parent component (the tool list) to each child component (the tool items), using single file templates.

In the child component, I get this error:

Property or method "..." is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

Where ... is any property of the tool data object, for example title or description.

Here's my setup:

Tools.vue (parent):

<template> <main id="tools"> <tool v-for="tool in tools" :data="tool" :key="tool.id"></tool> </main> </template> <script> import Tool from './Tool.vue' let test = { id: 1, title: 'Title', description: 'Description' }; export default { data() { return { tools: [ test ] } }, components: {'tool': Tool} } </script>

Tool.vue (child):

<template> <div class="tool"> <div class="title">{{ title }}</div> <div class="description">{{ description }}</div> </div> </template> <script> export default {} </script>

It should be simple, but I'm unable to find the solution with my google-fu. What am I missing here?

Categories: Software

Pass Attribute as a Component Parameter in Vue.js

Vuejs - Tue, 2017-07-25 22:18

I'm creating a test Component in Vue.js. I want to pass a parameter to use in my template as follows:

Vue.component('test', { props: ['href'], template: '<li><a href="{{href}}"><slot></slot></a></li>' });

In my html file:

<test href="/">Tvest</test>

But the property href is not binding to the attribute.

<li><a href="{{href}}">Tvest</a></li>

How can I do it properly in Vue.js?

Categories: Software

Is it possible to parse Vue.js data with jQuery?

Vuejs - Tue, 2017-07-25 21:51

There is this jQuery method:

$("#showNames").text("{{ $t('hide_labels') }}");

I'd like to set text taken from vue-i18n instance, dependent on user localization. When it's written this way, I get the literal moustache syntax contents. Is there any way to get the values displayed?

Categories: Software

Vue.js: how to load a template inside an async component

Vuejs - Tue, 2017-07-25 21:34

I'm brand new to Vue.js and I'm trying to get a simple site set up with it. I have a component for each page (About us, Contact us, etc).

This is my working starting point

Vue.component('about-us', { template: '<div>...lots of markup...</div>' });

I want to transform that code into something that works asynchronously. Attempting to follow the docs, here is my code:

Vue.component('about-us', function(resolve, reject){ let template_string = ''; // Load the template with ajax $.post(ajax_url, {'action': 'get_about_page'}, function(r){ r = JSON.parse(r); // Save the template string if( r.success ) { template_string = r.data; } }); // Resolve callback for Vue resolve({ template: template_string }); });

The error I get is:

[Vue warn]: Failed to mount component: template or render function not defined. found in ---> Anonymous Root

Question: is my approach wrong? Is it a syntax problem? I'm not sure if I'm on the right path. (yes I have jQuery loaded)

Categories: Software

Pages