Software

vue js nested array load to table

Vuejs - Tue, 2017-07-25 09:48

in vue js how to load nested array to a html table. when I use v-for inside v-for it qives an error Property or method "key" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

[ { jobtype_id:"1", jobtype_code:"L001", jobtype_name:"Labour", jobtype_order:"1", jobtype_comment:"1", jobs:[ { jobinvoicedtlid:"1", JobInvNo:"JBIN0016", JobCardNo:"", JobType:"1", JobCode:null, JobDescription:"Wheel alignment", JobQty:"2", JobPrice:"800.00", JobTotalAmount:"1600.00", JobDiscount:"0.00", JobNetAmount:"1600.00", JobDiscountType:"1", JobinvoiceTimestamp:"2147483647", Description:"Labour" }, { jobinvoicedtlid:"2", JobInvNo:"JBIN0016", JobCardNo:"", JobType:"1", JobCode:null, JobDescription:"Full Service", JobQty:"4", JobPrice:"250.00", JobTotalAmount:"1000.00", JobDiscount:"0.00", JobNetAmount:"1000.00", JobDiscountType:"1", JobinvoiceTimestamp:"2147483647", Description:"Labour" } ] }, { jobtype_id:"2", jobtype_code:"S002", jobtype_name:"Parts Outside", jobtype_order:"3", jobtype_comment:null, jobs:[ { jobinvoicedtlid:"3", JobInvNo:"JBIN0016", JobCardNo:"", JobType:"2", JobCode:null, JobDescription:"Oil Change", JobQty:"5", JobPrice:"500.00", JobTotalAmount:"2500.00", JobDiscount:"0.00", JobNetAmount:"2500.00", JobDiscountType:"1", JobinvoiceTimestamp:"2147483647", Description:"Parts Outside" } ] } ] <tbody> <tr v-for="item,key in printdata"> <td colspan='6'> <b>{{item.jobtype_name}}</b></td> <table border="1"> <tr v-for="itm in printdata.jobs"> <td>itm.JobDescription</td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </tr> </tbody>

Categories: Software

VueJS dynamic v-model value

Vuejs - Tue, 2017-07-25 09:16

I want to set v-model to a value dictated by the value in my v-for loop. here's my code:

<tr v-for="campaign in _campaigns"> <el-switch v-model="campaign.enabled"></el-switch> </tr>

now if campaign.enabled === 'active' i want to set v-model to on , or if
campaign.enabled === 'inactive' than off.

i tried to add logic to v-model in few ways like: v-model="campaign.enabled === 'active' ? on : off" or to use a method but none worked. Any idea what will consider as best practice to achieve that?

Categories: Software

Vuex Modules Structure

Vuejs - Tue, 2017-07-25 09:02

Tried to find this across tutorials and examples, but didn't find anything related. I know it is kind of up to the developer to structure it, but I was wondering how should be the best approach to the following:

I have a store, with modules like:

- root/ --- app-store.js --- modules/ ----- tasks.js ----- another-module.js

and so on.

I get the whole idea of modules, namespacing. But I'm not quite sure how to handle this situation (example):

1 - I access the list of Tasks. 2 - You click on a task in the list, it displays a view with all the details. 3 - You do some changes on this task (update, delete, etc)

What I'm doing right now:

  • one single file called 'tasks.js'

  • it loads all tasks with the information of each one nested already

  • when I click, I set a 'currentTaskId' variable. All actions references this variable when updating/deleting/etc

  • I'm loading the task list with the ID as the key, so I can easily reference it by tasks[id], instead of doing a search everytime.

My doubts:

  • Is this structure ok? Or should I create a module just to handle a single object?

  • Is using the ID as a Key for the array really a good practice?

  • Any other input. I know Vuex is quite flexible about the structure, but I find myself trying to come up with a nice structure, but I'm afraid of being overthinking something that should be simpler.

Categories: Software

Can’t access to custom canvas attribute in Vue

Vuejs - Tue, 2017-07-25 09:01

Has anyone used this component with Vue?

https://www.npmjs.com/package/aframe-draw-component.

I want to use Advanced Usage with “aframe-draw-component”. it works with raw html but not vue.js.

I get this error: App.vue?b405:124 Uncaught (in promise) TypeError: Cannot read property ‘canvas’ of undefined at NewComponent.init (eval at

It can’t find the custom dependency “draw”.

Can somebody help me ?

Thanks.

Categories: Software

Real Time Chat In Laravel [on hold]

Vuejs - Tue, 2017-07-25 09:01

I want to build chat system. Where users of website can have real time communication. I have searched for this in laravel. Most frequetly used solution is laravel pusher. But this is paid and free version is limited. Can anyone tell me how do i acheive this realtime chat without using pusher. I also looked for socket io but they also use pusher. can i use socket io or something else wihout pusher.

Categories: Software

Vuejs sidemenu transition not working with position: fixed

Vuejs - Tue, 2017-07-25 08:55

I have a sidebar component I would like to animate in and out with a transition. I am using transform translateX (see CSS below).

However, the menu does not animate in properly (although it animates out properly). It works fine when I get rid of the position: fixed css property on the component, however, that leaves it not looking like much of a sidemenu (it is not properly positioned on the screen). With position fixed, it works except that the background color and position of the sidemenu div (and elements within it) aren't finalized until after the animation is over.

So it looks gross. I've looked all over and found similar issues on here, but nothing that led me to a solution other than to use other peoples' pre-built components. (I would like to avoid doing that.)

Here is my html (from parent component) in webpack's vue-loader:-

<transition name="slide"> <app-menu v-if="menuToggled" :untoggle="toggleSidebar"> </app-menu> </transition>

Here is the sidemenu's CSS for the div:

.menu { position: fixed; top: 0; left: 0; bottom: 0; right: 0; display: flex; flex-direction: column; justify-content: space-between; background-color: black; padding: 10px; margin-right: 40px; text-align: center; }

Thanks! This is my first StackOverflow question. I hope I am not wasting anyone's time here. I very much appreciate constructive guidance of any form.

Categories: Software

How do I warn a user of unsaved changes before leaving a page in Vue

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

I have an UnsavedChangesModal as a component that needs to be launched when the user tries to leave the page when he has unsaved changes in the input fields (I have three input fields in the page).

components: { UnsavedChangesModal }, mounted() { window.onbeforeunload = ''; }, methods: { alertChanges() { } }
Categories: Software

Howler.js start playing song while it's loading

Vuejs - Tue, 2017-07-25 06:12

I'm using Howler.js

https://github.com/goldfire/howler.js

https://github.com/Blocklevel/vue-howler

I have it all working with preload and autoplay properties. But the problem is that some of the songs are a bit bigger in size. Is there any way to start playing the audio while it's loading. As soon as possible?

Categories: Software

vue init webpack alphalayui strange thing

Vuejs - Tue, 2017-07-25 05:55

My environment:
OS:win10
Vue:2.82
Yarn:0.27.5
Nodejs:8.2.1
Other:Git-bash When I first use vue init webpack alphalayui to build a vue project,I find a strange thing.

It can get my Email-ID,I fell so amazed,This Email-ID just use in a software which named Foxmail.But I have many Email-ID in this computer.

I want to know how can vue init get my Email-ID?

Can someone help me? Thanks in advance.
$ vue init webpack alphalayui ? Project name (alphalayui) y ? Project name y ? Project description (A Vue.js project) y ? Project description y ? Author (alphayan <yanyq@sdkej.com>) y ? Author y ? Vue build standalone ? Install vue-router? (Y/n) y ? Install vue-router? Yes ? Use ESLint to lint your code? (Y/n) y ? Use ESLint to lint your code? Yes ? Pick an ESLint preset (Use arrow keys) ? Pick an ESLint preset Standard ? Setup unit tests with Karma + Mocha? (Y/n) y ? Setup unit tests with Karma + Mocha? Yes ? Setup e2e tests with Nightwatch? (Y/n) y ? Setup e2e tests with Nightwatch? Yes

Categories: Software

In Vuejs, how to add watcher to all props and use the same function as a callback?

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

As the title, I want to add watcher and the same callback for all of the props, but I neet to code like this in sub-component:

<script> export default { props: { a: String, b: String, c: String }, watch: { a (v) { this.handler(v) }, b (v) { this.handler(v) }, c (v) { this.handler(v) }, }, methods: { handler (v) { // code... } } } </script>

And do you know how to simplify this?

Categories: Software

How to use PostCSS in Vue.js?

Vuejs - Tue, 2017-07-25 04:53

What's the recommended way to handle PostCSS in Vue.js (webpack template)?

I searched it in many places but still can't find a good solution.

Please, give an example using the most used plugins, like cssnext, precss and sugarss.

Categories: Software

How to warn unsaved changes when leaving a page in Vue?

Vuejs - Tue, 2017-07-25 04:25

I have several forms and input fields that I use in my Customize.vue file. I have to detect any unsaved changes and trigger a notification.

methods: { alertChange() { this.$notify.make('You have unsaved changes!', 'warning'); } }
Categories: Software

Vue Webpack Build Breaks Bulma CSS

Vuejs - Tue, 2017-07-25 03:07

I scaffold a webpack template for my vue project using the vue-cli. Subsequently, I added Bulma's CSS. When I run the program normally (npm run dev), the CSS renders properly. However, upon building the project for production (npm run build) with the default webpack configuration, the styling of the web app is now misaligned. Does anyone know how to resolve this issue?

For comparison:

Production Build of Vue with broken CSS

Dev version of Vue rendering CSS properly

The following is my webpack config (webpack.prod.conf.js)

var path = require('path') var utils = require('./utils') var webpack = require('webpack') var config = require('../config') var merge = require('webpack-merge') var baseWebpackConfig = require('./webpack.base.conf') var CopyWebpackPlugin = require('copy-webpack-plugin') var HtmlWebpackPlugin = require('html-webpack-plugin') var ExtractTextPlugin = require('extract-text-webpack-plugin') var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') var env = config.build.env var webpackConfig = merge(baseWebpackConfig, { module: { rules: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true }) }, devtool: config.build.productionSourceMap ? '#source-map' : false, output: { path: config.build.assetsRoot, filename: utils.assetsPath('js/[name].[chunkhash].js'), chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') }, plugins: [ // http://vuejs.github.io/vue-loader/en/workflow/production.html new webpack.DefinePlugin({ 'process.env': env }), new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false }, sourceMap: true }), // extract css into its own file new ExtractTextPlugin({ filename: utils.assetsPath('css/[name].[contenthash].css') }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. new OptimizeCSSPlugin({ cssProcessorOptions: { safe: true } }), // generate dist index.html with correct asset hash for caching. // you can customize output by editing /index.html // see https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ filename: config.build.index, template: 'index.html', inject: true, minify: { removeComments: true, collapseWhitespace: true, removeAttributeQuotes: true // more options: // https://github.com/kangax/html-minifier#options-quick-reference }, // necessary to consistently work with multiple chunks via CommonsChunkPlugin chunksSortMode: 'dependency' }), // split vendor js into its own file new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: function (module, count) { // any required modules inside node_modules are extracted to vendor return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexOf( path.join(__dirname, '../node_modules') ) === 0 ) } }), // extract webpack runtime and module manifest to its own file in order to // prevent vendor hash from being updated whenever app bundle is updated new webpack.optimize.CommonsChunkPlugin({ name: 'manifest', chunks: ['vendor'] }), // copy custom static assets new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), to: config.build.assetsSubDirectory, ignore: ['.*'] } ]) ] }) if (config.build.productionGzip) { var CompressionWebpackPlugin = require('compression-webpack-plugin') webpackConfig.plugins.push( new CompressionWebpackPlugin({ asset: '[path].gz[query]', algorithm: 'gzip', test: new RegExp( '\\.(' + config.build.productionGzipExtensions.join('|') + ')$' ), threshold: 10240, minRatio: 0.8 }) ) } if (config.build.bundleAnalyzerReport) { var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin webpackConfig.plugins.push(new BundleAnalyzerPlugin()) } module.exports = webpackConfig

Categories: Software

VueJS/Webpack - Images not loadng from list when image path is to local machine

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

I have a Vuejs project that I am using with Webpack.

Here is an example of how to render a list of images via VueJS:

https://jsfiddle.net/8mq9o7md/

<div id="app"> <ul id="example-1"> <li v-for="item in items"> <img :src="item.link" width="30px" height="30px"> </li> </ul> </div> var example1 = new Vue({ el: '#example-1', data: { items: [ { link: 'https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded' }, { link: 'http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons/3d-transparent-glass-icons-symbols-shapes/016945-3d-transparent-glass-icon-symbols-shapes-shapes-circle.png' } ] } })

Here the images are pulled from an external source via CDN. It works fine.

The problem occurs when the link to the images is from a local source (if I link to images located on my machine). For example:

items: [ { link: '../../images/localimage.png' }, { link: '../../images/localimage2.png' } ]

If I do this, it will fail to load. In Chrome in the console, it will output:

GET http://localhost:3000/item.link 500 (Internal Server Error)

This is what url-loader in my webpack.config.js file looks like:

module: { rules: [ { test: /\.(png|jpg|ttf|eot)$/, exclude: /node_modules/, use: [ { loader: 'url-loader?', options: { limit: 10000 } } ] } ] }

Note: The images I am trying to load are ~3kb each.

Categories: Software

How to concatenate data properties in VueJS

Vuejs - Tue, 2017-07-25 02:27

Basically I have a couple data strings in my data object, what I want, is to concatenate one the the strings, into the other. I want the user to be able to see the date of the last server update.

lastUpdate: "10/30/3033", message: 'Servers last updated: ',

So ideally it would display "message + lastUpdate" Also I cant just string it together in HTMl because I need to be able to swap out the message for other strings. I could seperate out my messages in html, but i want to learn if there is a more dynamic way to do this.

Putting it into the context of my code we have the following parent componenet:

<template> <div id="main-container" class="col-sm-12"> <h1>Server Display</h1> <p>{{message}}</p> <div id="mini-container" class="col-sm-3" v-for="(server, index) in servers"> <h3>({{index+1}}): {{server}}</h3> <mi-single-server :servers="servers" @serversReset="message = $event"></mi-single-server> </div> </div> </template> <script type="text/javascript"> import SingleServer from './SingleServer.vue'; export default{ data: function(){ return{ lastUpdate: "10/30/3033", servers: ['Blue', 'Aphex', 'Maxamillion', 'T180', 'T190', 'NW0'], message: 'Servers last updated: ' }; }, components: { 'mi-single-server': SingleServer } } </script>

What I would love to be able to do is to add something like the following to my data table

message: 'Servers last updated: ' + this.lastUpdate
Categories: Software

Vue JS dev server doesn't work in Atom

Vuejs - Tue, 2017-07-25 02:14

I started my website project in Visual Studio Code and it worked fine for days. I found out about Atom and decided to move over to it. Somehow whenever I start the dev server in Atom, each Vue component spits out:

Console output (pastebin)

"Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin"

and the webpage only renders

Cannot GET /

The dev server starts fine in Visual Studio Code but not in Atom

Categories: Software

Vue JS - How to use MySQL database

Vuejs - Tue, 2017-07-25 02:06

So I'm creating a web/ios/android app for my girlfriend and I so we can create To-do's which will insert them into a database and output them on a calendar in the app (many more features than that, but that's the gist)

Vue seemed easier than React to accomplish this (especially because I can't find any ease database-integration with React), but I've seen Crud for Vue.

My questions are: Can I use crud with MySQL? Will one code-base run on windows browser, ios, and android?

OR: If I use SlimPHP to create a Rest API and then use Vue for the responses, is this something that would run one code-base on windows browser, ios, and android?

I'm hoping I can use SlimPHP to be honest, but if I can't do either, could anybody let me know what the EASIEST way to accomplish this is?

Thank you!

Categories: Software

How to define property with a component?

Vuejs - Tue, 2017-07-25 01:52

I currently have three steps in a form that I want to show sequentially, so I created three components - one for each step of the process.

import LocationList from './components/LocationList.vue'; import ChooseTime from './components/ChooseTime.vue'; import ChooseMethod from './components/ChooseMethod.vue'; Vue.component('location-list', LocationList); Vue.component('choose-time', ChooseTime); Vue.component('choose-method', ChooseMethod); let store = { isVisible: { steps: { one: true, two: false, three: false, } } }; new Vue({ el: '#app-order', data: store, router });

Now, when my one and only route is called, all these components are being loaded properly. The issue is that when I try to v-show them one at a time:

<location-list v-show="isVisible.steps.one"></location-list> <choose-time v-show="isVisible.steps.two"></choose-time> <choose-method v-show="isVisible.steps.three"></choose-method>

The error message I receive though is:

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

But when I check within Vue's browser extension, isVisible is defined within the root element?

Thanks for any help!

Categories: Software

Vue.js / webpack creates no build file?

Vuejs - Tue, 2017-07-25 00:19

This might be a stupid question but what the hell.

I am using the vue-cli webpack-simple template, in the webpack config of this project I find the following:

output: { path: path.resolve(__dirname, './dist'), publicPath: '/dist/', filename: 'build.js' },

No file is being built though. When running the webpack server I can access the file through the browser though. Is the build.js file only available when the webpack development server is running?

Is this what defines runtime vs standalone? Even after reviewing the documentation I am still confused what the exact difference is.

I need a compiled file since I am trying to publish a transpiled file to publish my package to NPM.

Cheers.

Categories: Software

Vue.js - how to render nested component in this simple example?

Vuejs - Mon, 2017-07-24 23:10

Im lost. I dont know and I dont understand how can I correctly register and render component nested in other component. Run this example please, click on About link a look to console. There is warning about component registering.

var appLayout = { template: ` <div id="app" class="container"> <header> <slot name="header"></slot> </header> <slot></slot> <footer> <slot name="footer"></slot> </footer> </div> ` } var home = { template: ` <main> <h3>Home</h3> </main> ` } var about = { template: ` <main> <nested-component></nested-component> </main> ` } var nestedComponent = { template: ` <main> <h3>About</h3> </main ` } var routes = [ { path: '/', component: home }, { path: '/about', component: about } ] var router = new VueRouter({ routes }) new Vue({ template: '#app', router, components: { appLayout } }).$mount('#app') .fade-enter-active, .fade-leave-active { transition-property: opacity; transition-duration: 0.4s; } .fade-enter-active { transition-delay: 0.2s; } .fade-enter, .fade-leave-active { opacity: 0; } <template id="app"> <app-layout> <nav slot="header"> <router-link to="/">Home</router-link> <router-link to="/about">About</router-link> </nav> <transition name="fade"> <router-view></router-view> </transition> <p slot="footer"> Copyright notice </p> </app-layout> </template> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.1/vue.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-router/2.7.0/vue-router.min.js"></script>

Categories: Software

Pages