Vuejs

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

Resolve error Cannot find Module .vue in Webpack build

Tue, 2017-08-08 14:52

I am trying to bundle my and code using and I'm receiving the error

Cannot find module 'path/file.vue'

According to this question, I need to generate .d.ts files which I have done using vuetype. The .d.ts files are in the same directory as the .vue files. This structure satisfies my linter so it doesn't show errors, but when I try to build with Webpack, I receive the error. How can I tell webpack where to find my .vue files?

webpack.config.js const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); module.exports = { entry: { Evaluations: './WebResources/js/Evaluations.ts' }, devServer: { contentBase: './dist' }, module: { rules: [{ test: /\.ts$/, exclude: /node_modules|vue\/src/, loader: 'ts-loader', exclude: /node_modules/, options: { appendTsSuffixTo: [/\.vue$/] } }, { test: /\.vue$/, loader: 'vue-loader', options: { esModule: true } }, { test: /\.css$/, use: [ 'style-loader', 'css-loader' ] }, { test: /\.(png|svg|jpg|gif)$/, use: [ 'file-loader' ] }, ] }, resolve: { extensions: [".tsx", ".ts", ".js", ".vue"], alias: { 'vue$': 'vue/dist/vue.esm.js' } }, plugins: [ new CleanWebpackPlugin(['dist']), new HtmlWebpackPlugin({ filename: 'Evaluations.html', template: './WebResources/html/Evaluations.html' }), new webpack.optimize.CommonsChunkPlugin({ name: 'WebAPI' }) ], output: { filename: '[name].bundle.js', path: path.resolve(__dirname, 'dist') } } Evaluations.ts "use strict"; import Vue from 'vue'; import CommentBox from '../components/CommentBox.vue'; import SignOff from '../components/SignOff.vue'; import Rating from '../components/Rating.vue'; import Competency from '../components/Competency.vue'; import EvaluationMain from '../components/EvaluationMain.vue'; new Vue({ el: "#evaluations-app", components: { 'comment-box': CommentBox, 'sign-off': SignOff, 'rating': Rating, 'competency': Competency, 'evaluation': EvaluationMain } });

I did try to add 'CommentBox$' : '../WebResources/components/CommentBox.vue' to my webpack config file, but without success. I also tried a variety of locations inside node_modules for my .d.ts files, but without success. It's possible I did not put them in the correct location in node_modules.

Categories: Software

I need to inject plugins in my tests otherwise I get an ERROR LOG

Tue, 2017-08-08 14:48

I'm wanting to test a component where I call $t() to translate my texts and this.$route.name.

The test I created passes but with many ERROR LOG:

ERROR LOG: '[Vue warn]: Error in render function: "TypeError: undefined is not a function (evaluating '_vm.$t('contact')')"

ERROR LOG: '[Vue warn]: Error in mounted hook: "TypeError: undefined is not an object (evaluating 'this.$route.name')"

Here is my main.js

import Vue from 'vue'; import VueI18n from 'vue-i18n' import router from './router'; import messages from './messages'; Vue.use(VueI18n); const i18n = new VueI18n({ fallbackLocale: 'fr', locale: 'fr', messages, }); Vue.config.productionTip = false let vm = new Vue({ el: '#app', i18n, router, }); // Once page is reloaded i18n.locale = vm.$route.params.locale;

And here is my test: MyComponent.spec.js

describe('MyComponent', () => { // other tests on the object MyComponent (not its instance) // Mount an instance and inspect the render output it('renders the correct message', () => { const Ctor = Vue.extend(MyComponent); const vm = new Ctor().$mount(); }); });

When I try to inject i18n:

const vm = new Ctor(new VueI18n({fallbackLocale: 'fr', locale: 'fr', messages,})).$mount();

I get this error

PhantomJS 2.1.1 (Linux 0.0.0) ERROR TypeError: undefined is not an object (evaluating 'Vue.config')

Categories: Software

Chrome ask for track-by but not firefox

Tue, 2017-08-08 14:41

I'm working on vueJs in symfony project. I have a vue that worked great until few days. I didn't change anything that have something to do with that vue but with no reason since few days, it doesn't work on chrome (wich i use since the beggining) but works great on firefox.

So what I do is a select :

<select v-model="selectedStock"> <option :value="stock.id"v-for="stock in stocks">{{ stock.name }}</option> </select>

my "stocks" ara init with that :

loadStocks () { this.$http({ url: 'api/stocks', method: 'get' }).then( response => { this.stocks = response.data }) },

and my function called by the route api/stocksis :

public function indexAction () { $em = $this->getDoctrine()->getManager(); $stocks = $em->getRepository('RBOrdersBundle:Stock')->findAll(); return new JsonResponse($this->get('rb.serializer')->onEntity($stocks)->toArray()); }

and when i'm going on local/api/stocks I have an array with 2 object

and when in loadStocks() in the response part I do : alert(typeof response.data) chrome give me string and firefox give me Object

And finally the console in chrome show me :

main.js:39752 [Vue warn]: Duplicate value found in v-for="stock in stocks": "0". Use track-by="$index" if you are expecting duplicate values. (found in component: <reassort-tool>) but like 20 times with a bunch of different letter and I'm pretty sure there is no duplicate in my array

Categories: Software

action function does not recongize data vuex

Tue, 2017-08-08 13:40

i am trying to do a switch case based on a select list that i have on my component.

<div class="col-md-7"> <select class="form-control" id="sel1" v-model="getDocumentSettings.margin" @change="customMargin(getDocumentSettings.margin)"> <option v-for="item in getMarginOptions">{{item}}</option> </select> </div>

getMarginOptions is a computed propertie that returns me a list of choices, that can be

marginOptions: [ "Custom", "Normal", "Narrow", "Moderate", "Wide", "Mirrored", "Office Default" ]

this data is in vuex store and is retrieved, my problem is to change other data based on the selection, when a user select a propertie i want to change margins(left,right,top,bottom) that i have in this object(inside vuex too)

Doc: { key: "Document", left: 0, right: 0, top: 0, fileName: "", bottom: 0, margin: "Custom", },

so i put a swtich case inside my vuex like this:

actions: { customMargin(obj) { switch (obj.data) { case "Custom": obj.type.Doc.left = 0; obj.type.Doc.right = 0; obj.type.Doc.top = 0; obj.type.Doc.bottom = 0; break; case "Normal": obj.type.Doc.left = 1; obj.type.Doc.right = 1; obj.type.Doc.top = 1; obj.type.Doc.bottom = 1; break; case "Narrow": obj.type.Doc.left = 0.5; obj.type.Doc.right = 0.5; obj.type.Doc.top = 0.5; obj.type.Doc.bottom = 0.5; break; case "Moderate": obj.type.Doc.left = 0.75; obj.type.Doc.right = 0.75; obj.type.Doc.top = 1; obj.type.Doc.bottom = 1; break; case "Wide": obj.type.Doc.left = 2; obj.type.Doc.right = 2; obj.type.Doc.top = 1; obj.type.Doc.bottom = 1; break; case "Mirrored": obj.type.Doc.left = 1.25; obj.type.Doc.right = 1; obj.type.Doc.top = 1; obj.type.Doc.bottom = 1; break; case "Office Default": obj.type.Doc.left = 1.25; obj.type.Doc.right = 1.25; obj.type.Doc.top = 1; obj.type.Doc.bottom = 1; break; default: obj.type.Doc.left = 0; obj.type.Doc.right = 0; obj.type.Doc.top = 0; obj.type.Doc.bottom = 0; break; } } }

it should receive a state object so i can access my doc,and the option that was selected, this is how i call it:

methods: { customMargin(option) { this.$store.dispatch({ type: 'customMargin', data: option }) }, },

i think 1 of my problem is the way how i handle actions with vuex, i want to send the option from the select and change the doc margin inside vuex.

Any help?

Categories: Software

vuejs: removed child component can still get event message from parent

Tue, 2017-08-08 13:18

I came across this issue in my project, and I reproduce it in the following demo: https://jsfiddle.net/baoqger/jeeh5ncp/

Briefly speaking,

var demo = new Vue({ el: '#demo', data: { newitem: '', allData: [], }, methods: { addItem() { this.allData.push(this.newitem); }, sendMessage() { Bus.$emit('send-message'); }, showAll() { console.log(this.allData.length); }, }, })

I use addItem method add item to the allData property,which is a list. And sendMessage to emit event out, which will be listened by child component. The showAll is simply show the current length of the allData list.

for the child component, it goes as following :

Vue.component('service', { template: '<div>' + '<span>{{serviceName}}</span>' + '<button @click="remove">X</button>' + '</div>', props: ['serviceName', 'index'], methods: { remove() { this.$emit('remove'); }, }, created() { Bus.$on('send-message', () => { console.log(this.index); }) }, })

Each child component can be removed by click the x button. And in the created hook, set up the event listen for send-message.

the HTML part is as following:

<div id="demo"> <input v-model="newitem"> <button @click="addItem">Add</button> <button @click="sendMessage">Send Message</button> <button @click="showAll">Show</button> <service v-for="(each, index) in allData" :service-name="each" @remove="allData.splice(index,1)" :index="index"></service> </div>

The confusing point is, for example I add 3 child component. And click the send Message button, I can get 0 1 2, which is expected. But if I remove one child element, and click the send Message button, still get 0 1 2. But the length is 2. So what's wrong with that?

Categories: Software

Getting a random number (1 to 6 number like dice) object from an array, then remove it from array

Tue, 2017-08-08 13:04
var data = [ { id:1, account_name:'Akshay Patil', debit:111, credit:'' }, { id:2, account_name:'Bharat Chavan', debit:222, credit:'' }, { id:3, account_name:'Chetan Kore', debit:333, credit:'' }, { id:4, account_name:'Dilip Patil', debit:444, credit:'' }, { id:5, account_name:'Eshawr Dange', debit:555, credit:'' }, { id:6, account_name:'farhan Khan', credit:666, debit:'' }, { id:7, account_name:'Ganesh Shine', credit:777, debit:'' }, { id:8, account_name:'Hemant Birje', credit:888, debit:'' } ]

problem happen when object remove from array after random number are generated that time is random number is greater than array of length then error like Cannot read property.

Categories: Software

cannot use v-for on stateful component root element in VueJS

Tue, 2017-08-08 12:28

I'm trying to build small application on Vuejs 2.0 where I'm having component file named Text.Vue and following are the components:

<template> <!-- Post --> <div class="blog-item" v-for="item in items"> <!-- Post Title --> <h2 class="blog-item-title font-alt"><a href="#">{{ item.title }}</a></h2> <!-- Author, Categories, Comments --> <div class="blog-item-data"> <a href="#"><i class="fa fa-clock-o"></i> {{ item.created_at }} </a> <span class="separator">&nbsp;</span> <a href="#"><i class="fa fa-user"></i> John Doe</a> <span class="separator">&nbsp;</span> <i class="fa fa-folder-open"></i> <a href="">Design</a>, <a href="#">Branding</a> <span class="separator">&nbsp;</span> <a href="#"><i class="fa fa-comments"></i> 5 Comments</a> </div> <!-- Text Intro --> <div class="blog-item-body"> <p> {{ item.content }} </p> </div> <!-- Read More Link --> <div class="blog-item-foot"> <a href="#" class="btn btn-mod btn-round btn-small">Read More <i class="fa fa-angle-right"></i></a> </div> </div> <!-- End Post --> </template> <script> export default { data() { return { title: 'POST WITH TEXT ONLY', contents: 'Suspendisse accumsan interdum tellus, eu imperdiet lacus consectetur sed. Aliquam in ligula ac lacus blandit commodo vel luctus quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras eu ultrices mauris.', date_time: '4 December', items: [] } }, beforeCreate() { axios.get('/Blog/api/posts').then(response => { if(response.status === 200) { this.items = response.data.posts } }) } } </script>

While doing npm run dev or compiling the asset file I'm getting and error:

  • Cannot use v-for on stateful component root element because it renders multiple elements.

I don't know where I'm doing mistake, help me out in this.

Thanks

Categories: Software

How to acces external json file objects in vue.js app

Tue, 2017-08-08 12:03

How to access JSON objects in the vue.js app I am new in this

import json from './json/data.json'

the JSON file is loaded and now I have to access the objects within it

Categories: Software

Vue: Template displays only one time

Tue, 2017-08-08 11:58

I'm starting with Vue.js and I'm struggling with the components part.

I've created a component with a template and some data, I want the code to be triggered after creating a new item (cocoon:after-insert event here) :

$(document).ready -> $('*[data-iceberg]').each -> new Iceberg($(this)) $('table.list').on 'cocoon:after-insert', (event, inserted) -> new Iceberg($(inserted), "add") if inserted? $('*[data-unit-name]').each -> $(this).find('.item-population-unit-name').html($(this).attr('data-unit-name')) Vue.component('storing', { template: '<span> {{storingArea}} - {{quantity}} </span>', data: -> { storingArea : 'No area', quantity: 0 } }) new Vue { el: '#storingDisplay' }

HTML/HAML part (the component is called on the 5th '%td') :

%tbody.nested-fields.delivery-item.incoming-parcel-item{ data: { iceberg: true } } %tr.item-display.hidden %td.act - if f.object.destroyable? = link_to_remove_association(content_tag(:i) + h(:destroy.tl), f, 'data-no-turbolink' => true, class: 'destroy remove remove-item') %td.act = link_to("#", class: 'edit edit-item', data: { edit: "item-form" }) do %i = :edit.tl %td %label{ data: { item_value: "input.parcel-item-variant" } }= f.object.variant ? f.object.variant.name : '??????' %label{ data: { item_value: "input.item-non-compliant" } }= non_compliant_message if f.object.non_compliant? %td %label %span{ data: { item_value: "span.total-quantity" } }= f.object.population %span{ data: { item_value: "span.item-population-unit-name" } }= f.object.variant ? f.object.variant.unit_name : '#' %td #storingDisplay %storing %td %label{ data: { item_value: "input.item-delivery-mode:checked" } }= f.object.delivery_mode

The current behavior is that my component is well called and the template rendered correctly on the first item created but only on the first one, it is not on the following ones even if i'm seing <storing></storing> when inspecting the element where the template should be displayed. enter image description here

I'm probably not using the good practices to achieve what I want and i'm losing myself in the documentation so some help would be welcome :)

Categories: Software

Add jsColor lib to vue component

Tue, 2017-08-08 11:56

I am trying to add the simple jsColor lib to my vuejs project, i am working with webpack simple in vueJS.

So i want to add my script to this component:

<template> <div> <h3 class="text-center">Paragraph</h3> <div class="form-group"> <label for="fontSize" class="control-label col-md-2">font-size</label> <div class="col-md-2"> <input v-model="paragraph.fontSize" type="number" min="1" class="form-control"> </div> <div class="col-md-1"> <img class="changeColor" @click="alignment('left')" width="30" height="30" src="../../assets/left-alignment.png" /> </div> <div class="col-md-1"> <img class="changeColor" @click="alignment('center')" width="30" height="30" src="../../assets/center-alignment.png" /> </div> <div class="col-md-1"> <img class="changeColor" @click="alignment('right')" width="30" height="30" src="../../assets/right-alignment.png" /> </div> <div class="col-md-1"> <img class="changeColor" @click="alignment('justify')" width="30" height="30" src="../../assets/justify.png" /> </div> <div class="col-md-1"> <span>{{paragraph.align}}</span> </div> </div> <div class="row"> <div class="col-md-offset-2 col-md-6"> Color: #<input class="jscolor" v-model="paragraph.color"> </div> </div> <div class="form-group"> <label for="paragraph" class="control-label col-md-2">Text</label> <div class="col-md-8"> <textarea v-model="paragraph.text" class="form-control" rows="5" id="comment"></textarea> </div> </div> <div class="col-md-offset-2 col-md-8"> <button @click.prevent="addParagraph()" class="btn btn-success btn-block">Add Paragraph</button> </div> </div> </template> <script> import jsColor from '../../static/js/jscolor.js'; export default { data() { return { paragraph: { text: "", fontSize: 14, key: "Paragraph", align: "left", color: "000000", paragraph: {} } } }, methods: { addParagraph() { var paragraph = { key: this.paragraph.key, text: this.paragraph.text, fontSize: this.paragraph.fontSize, align: this.paragraph.align, } this.$store.commit("appendToDocument", paragraph) var panelObj = {"section":"paragraph","color":"list-group-item-success","action":"added"}; this.$store.commit("appendToPanel", panelObj); }, alignment(option) { this.paragraph.align = option; } }, } </script> <style> .margin-above { margin-top: 40px } .changeColor { padding: 5px; } .changeColor:hover { background-color: gray; } </style>

i already tried to add the import and the require, the only thing that worked was to use the mounted function inside vuejs lifecycle, but the problem is that it just reflects on the first page load, if open the component again the script is not working.

Any help?

Categories: Software

Migrating from vue1 to vue2

Tue, 2017-08-08 11:55

I'm trying to migrate this sample dropdown menu from vue1 to vue2.

http://vuejsexamples.com/vue-dropdown-menu/

I've changed the ready method to mounted, removed the json filter and rewrote the for loop in close because it caused errors in the console.

Right now there aren't any errors while I run this, but still, the dropdown doesn't work properly - it does not close when I click outside of the menu. Can anybody help with migrating this?

new Vue({ el: '#menu', mounted: function() { var self = this window.addEventListener('click', function(e){ if (! e.target.parentNode.classList.contains('menu__link--toggle')) { self.close() } }, false) }, data: { dropDowns: { ranking: { open: false} } }, methods: { toggle: function(dropdownName) { this.dropDowns[dropdownName].open = !this.dropDowns[dropdownName].open; }, close: function() { for (var i = 0; i < this.dropDowns.length; i++) { this.dropDowns[dd].open = false; } } } }) body { margin: 2rem 0; } ul { list-style: none; } .menu { display: flex; } .menu__item { position: relative; padding-right: 3rem; } .menu__link { text-transform: uppercase; } .menu__icon { margin: 0 !important; } .open .dropdown-menu { display: block; } .dropdown-menu { font-size: 0.9rem; position: absolute; min-width: 130px; top: 2.2rem; display: none; box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.2); border-radius: 4px; } .dropdown-menu__item:first-child .dropdown-menu__link { border-top-left-radius: 4px; border-top-right-radius: 4px; } .dropdown-menu__item:last-child .dropdown-menu__link { border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; } .dropdown-menu__link { display: block; padding: 1rem; color: blue; background-color: #fafafa; } .dropdown-menu__link:hover { color: green; background-color: #ccc; } <script src="https://unpkg.com/vue@2.4.2/dist/vue.min.js"></script> <div id="menu"class="row"> <ul class="menu"> <li class="menu__item"> <a class="menu__link" href="#">Home</a> </li> <li class="menu__item menu__item--dropdown" v-on:click="toggle('ranking')" v-bind:class="{'open' : dropDowns.ranking.open}"> <a class="menu__link menu__link--toggle" href="#"> <span>Rangliste</span> <i class="menu__icon fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <li class="dropdown-menu__item"> <a class="dropdown-menu__link" href="#">Aktuelle Runde</a> </li> <li class="dropdown-menu__item"> <a class="dropdown-menu__link" href="#">Siegerliste</a> </li> </ul> </li> <li class="menu__item"> <a class="menu__link" href="#">Belegungskalender</a> </li> </ul> <pre>{{ dropDowns }}</pre> </div>

Categories: Software

Is it possible to refer to a global bus in the template of a component?

Tue, 2017-08-08 11:36

I use a global bus to manage emitted and received events between components (sibling to sibling and child to parent). bus is defined as window.bus = new Vue() (which I know is not recommended but I failed to use import in a sustainable way).

It works fine but one drawback of such an approach is that I have to use a handler in the template of my component:

<template> (...) <div v-for="c in aList" v-on:click="emitcasedetails(c)">something</div> (...) </template> <script> export default { (...) methods: { emitcasedetails: function (c) { bus.$emit('casedetails', c._source) }, (...) } </script>

Again, this works fine but requires extra code.

I tried to directly

<div v-for="c in aList" v-on:click="bus.$emit(c._source)">something</div>

but bus is not defined when running the app.

Is a direct reference to the bus in the component's template possible or do I absolutely have to go via a handler?

Categories: Software

Async and await in Vuejs

Tue, 2017-08-08 11:29

I have trouble retrieving data from a REST-API using VueJS, axios, Async/Await with Promise(??). I need to call two different REST-APIs. One is giving me a list and I can iterate through it, which is fine.

<template> <div> <div v-if="posts && posts.length"> <div v-for="post of posts"> {{post.name}} <img :src="getUserPicturePath(post.name)" /> </div> </div> </div> </template>

The other, as you can see, in between the v-for, is calling a method which is using axios.

<script> import axios from 'axios' export default { data: () => { posts: [] } created() { // a method to fill up the post-array }, methods: { async getUserPicturePath(name){ const response = await axios.get('linkToApi'+name) console.dir(response.data.profilePicture.path) return response.data.profilePicture.path } } } </script>

The console.dir(response.data.profilePicture.path)- Part is giving the correct Path to the profilePicture, but the <img :src="getUserPicturePath(post.name)" /> above in the <template>, writes [Object Promise].

Any suggestion how I can get the path?

Categories: Software

Prevent back button to work on iframe in vue app

Tue, 2017-08-08 11:04

I have single page website, which I develop using vue.js. My main page, 'A', contains two iframes 'B' and 'C', which prevent from the 'back' button from working on the 'A'.

The wanted behavior is that the 'back' bypass the iframe, and influence only on the main page 'A'.

Just for testing, I added a fictive button 'back', which works as wanted on the parent page 'A':

<button @click="back"> back </button> methods: { 'back': function () { window.history.go(-3) } }

How should I bypass the native 'back' behavior to work on the parent page?

Categories: Software

Open PDF in a new tab using domPDF and axios

Tue, 2017-08-08 10:47

My controller

$pdf = PDF::loadView('pdf', $data); $pdf->setPaper('a6', 'landscape')->setWarnings(false); return $pdf->stream();

My function in VueJS

preview() { axios.post('/orders/preview') .then(function (response) { window.open("data:application/pdf," + encodeURI(response.data)); }) .catch(function (error) { // Error callback }); }

However I get this string in return

%PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R 10 0 R 13 0 R 18 0 R 21 0 R ...

If I try to open that with window.open it just opens an empty page... Should domPDF not open a new tab automatically with ->stream()? Or how can I open the pdf with the given string in JS?

Categories: Software

How add dynamic ref in vue?

Tue, 2017-08-08 10:36

I have some dynamic <input> elements in my dom rendered from for loop in vue. I need to add ref property to each of them by appending an Id to each ref like element1,element2,..etc. How to do this in vue?

<div v-for="(result, index) in data" :key="index"> <input type="text" type="file" ref="element" /> </div>

How to add ref if result.id exists

Categories: Software

Json module not found vue.js using webpack

Tue, 2017-08-08 10:27

I am trying to import a JSON file into my main.js file using this:

import json from 'json/data.json'

Here is my JSON loader and I have also included the loader configurations:

{ test: /\.json$/, loader: 'json' }

Here is the error I am receiving:

ERROR in ./src/main.js Module not found: Error: Cannot resolve module 'json/data.json' in C:\pathto\project\src @ ./src/main.js 27:12-37

Categories: Software

original size of image file with vuejs

Tue, 2017-08-08 10:20

at the moment i am doing a file upload, basicly when i select a file i can edit his width and height and other stuffs, but my problem is related to the width and weight, basicly what i need is to get the width and height of the original image size, at the moment i can change it and it is working nice.

So i have this:

<div id="holder" class="col-md-offset-2"> <div v-if="!image"> <input type="file" @change="onFileChange"> </div> <div v-else> <div class="col-md-6"> <div class="form-group"> <label class="control-label col-md-2">width</label> <div class="col-md-10"> <input class="form-control" v-model="docImage.width" type="number" /> </div> </div> <div class="form-group"> <label class="control-label col-md-2">height</label> <div class="col-md-10"> <input class="form-control" v-model="docImage.height" type="number" /> </div> </div> data() { return { image: '', docImage: { key: 'Image', width: '100', height: '100', base64: "", align: "left", }, alignChoices: [ 'left', 'right', 'center' ] } }, onFileChange(e) { var files = e.target.files || e.dataTransfer.files; if (!files.length) return; this.createImage(files[0]); }, createImage(file) { var image = new Image(); var reader = new FileReader(); var vm = this; reader.onload = (e) => { vm.image = e.target.result; vm.docImage.base64 = vm.image.split(",")[1]; // get the base64 string defined after the comma }; reader.readAsDataURL(file); }, removeImage: function (e) { this.image = ''; },
Categories: Software

Symfony3 + Vuejs nginx configuration

Tue, 2017-08-08 10:06

I'm currently coding an app using SF3 for the back and VueJs for the front.

I use a controller action with the base route '/' to render the main template (with twig) containing the link to js files and the div binding for VueJs

The Vuejs app is a single page app and uses vue-router. The vue-router mode is set to history in production mode, that's where i have some trouble. The dev config uses the hash so no problem.

I would like to configure my nginx so that :

  1. Checks if it matches a vuejs route
  2. If not check that it matches a symfony route
  3. If not then redirect to some 404 page

1 and 2 can be revert.

My current nginx location is (the default symfony one):

location / { try_files $uri /app.php$is_args$args; }

The issue is that when i reload a vuejs route in the browser i have a 404 errors, however navigating route to route works fine.

If it helps, all my symfony routes are prefixed by api/ or admin/

Thanks for your help !

Categories: Software

How to make Vue router from outside?

Tue, 2017-08-08 09:54

I have very simple page with routing. Like:

... const NotFound = { template: '<p>Page not found</p>' } const Home = { template: '<p>home page</p>' } const Faq = { template: '<p>Faq page</p>' } const routes = [ {path: '/', component: Home}, {path: '/book', component: Book}, {path: '/faq', component: Faq}] const router = new VueRouter({ routes, // short for `routes: routes` mode: 'history' }) ...

Links works inside Vue app. But if I am trying to access directly to site.com/book I am getting 404 error page. I understand that it's virtual routing and it's do not exists on the server. But is there any way to fix it?

If I right remember there was trick with #, but I want to URL directly without any hashes.

Categories: Software

Pages