Software

Import style file doesn’t scoped?

Vuejs - Thu, 2017-09-14 08:54

when I try to import CSS file like this, the CSS doesn't scoped.

must write style in style tag that can be work ???

I use the vue-cli to try this

<style scoped> @import "hell.css"; </style>
Categories: Software

How can I reload a vue component?

Vuejs - Thu, 2017-09-14 07:37

I know the solution is update the prop data like this :

this.selectedContinent = ""

But I want to use another solution

After I read some reference, the solution is :

this.$forceUpdate()

I try it, but it does not work

Demo and full code like this :

https://jsfiddle.net/Lgxrcc5p/13/

You can click button test to try it

I need a solution other than update the property data

Categories: Software

Bulma's navbar-buger doesnt connect to menu items in Vue.js 2

Vuejs - Thu, 2017-09-14 07:30

I am trying to implement a navbar for my application whose front end is built using Vue 2.0 and Bulma . It works well on desktops and but on smaller screens its showing the burger icon but it is not showing any elements. Its just present.

<template> <div class="container is-fluid"> <div> <nav class="navbar is-dark"> <div class="navbar-brand"> <a class="navbar-item" href="#"> <img alt="K R O N O S" height="100px"> </a> <div class="button navbar-burger" data-target="navMenu"> <span></span> <span></span> <span></span> </div> </div> <div class="navbar-menu" id="navMenu"> <div class="navbar-end"> <div class="navbar-item"> <a class="" href="#"> Docs </a> </div> <div class="navbar-item "> <a class="" href="#"> Report </a> </div> <div class="navbar-item"> <a class="">More</a> </div> <div class="navbar-item"> <a class="">Logout</a> </div> </div> </div> </nav> </div> </div> </template> <script> document.addEventListener('DOMContentLoaded', function () { // Get all "navbar-burger" elements var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0) // Check if there are any navbar burgers if ($navbarBurgers.length > 0) { // Add a click event on each of them $navbarBurgers.forEach(function ($el) { $el.addEventListener('click', function () { // Get the target from the "data-target" attribute var target = $el.dataset.target var $target = document.getElementById(target) // Toggle the class on both the "navbar-burger" and the "navbar-menu" $el.classList.toggle('is-active') $target.classList.toggle('is-active') }) }) } }) export default { name: 'Navbar', data () { return { msg: '' } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> div{ border: 0px solid black; } </style>

As you can see I have tried implementing the example code in on which was present here but with no use. Shouldnt Bulma give me responsive navbar out of the box. All the examples and solutions I have found are for the older "nav" class not the newer "navbar". Help would be much appreciated.

Categories: Software

Can we use selenium webdriver to automate VueJS applications?

Vuejs - Thu, 2017-09-14 07:24

I am trying to build a selenium fraewmork for an application which is based on VueJS.It would be great help if somebody can share their knowledge on this topic as it will me in taking a better decision.

Categories: Software

render custom tag from REST API response

Vuejs - Thu, 2017-09-14 06:48

I have the following component MyComponent.vue:

<template> <div v-html="content"></div> </template> <script> import Vue from 'vue' import CustomComponent from 'CustomComponent.vue' Vue.use(CustomComponent) export default { name: `my-component`, computed: { content() { return this.$store.state.content } } // ... } </script>

Where this.$store.state.content is html-string which I get from REST API. For example:

<custom-component data-count="1"></custom-component><p>some text</p>

custom-component tag is not rendered in may case.

Is it possible to render vue component from html-string which I get from REST API and if I use this string in v-html?

Categories: Software

Using a product tour library with VueJS

Vuejs - Thu, 2017-09-14 05:28

I'm trying to setup a feature intro tutorial for my web app (like intro.js). I'm having trouble with intro.js with nothing happening (no error message or tour messages). I tried setting up the data attributes that intro.js uses and calling the tour start from the mounted function on App.vue, but no luck. I'm looking to see if anyone has experience with with libraries like this combined with VueJS.

Code from App.vue:

mounted: function() { const introJS = require('intro.js') introJS.introJs().start() }

Inside of the same component in it's <template>:

<div class="card card-accent-info" v-if="!isLoading" data-intro="Test step here" data-step="1">

I also have the css loaded in App.vue:

@import "~intro.js/minified/introjs.min.css";

Categories: Software

Spark is not defined

Vuejs - Thu, 2017-09-14 03:59

I using spark in laravel with vue.js. I add in home.blade.php and I got this error:

Uncaught ReferenceError: Spark is not defined

what I had done:

php artisan spark:install
Categories: Software

Call parent method with component

Vuejs - Thu, 2017-09-14 02:15

I have a component and want to add a click listener that runs a method in the parent template in Vue. Is this possible?

<template> <custom-element @click="someMethod"></custom-element> </template> <script> export default { name: 'template', methods: { someMethod: function() { console.log(true); } } </script>
Categories: Software

VueJS Element vue-data-tables Search box filter with range

Vuejs - Wed, 2017-09-13 20:56

I am using VueJS 2.0 along with http://element.eleme.io and https://njleonzhang.github.io/vue-data-tables. Been trying to figure out how I can do a ranged search (X to Y) with https://njleonzhang.github.io/vue-data-tables/#/searchBoxFilter but unable to figure it out and could not find any examples. I feel like it can be done with the filterFunction, but unsure. Or maybe just add more text inputs that can take two numbers, and pass those values to the filterFunction? I am not really sure so if anyone has a example on how this is done, I would extremely appreciate it. Below is what I have so far, I removed everything I tried, to not confuse anyone.

<template> <data-tables ref="multipleTable" :data="tableData" :pagination-def="paginationDef" :search-def="searchDef" @filtered-data="handleFilteredData" @selection-change="handleSelectionChange"> <el-row slot="custom-tool-bar" style="margin-bottom: 10px"> <el-col> <el-button @click="hideFilteredData()" type="primary">Delete Filtered</el-button> <el-button @click="hideSelectionData()" type="primary">Delete Selected</el-button> </el-col> </el-row> <el-table-column type="selection" width="55"> </el-table-column> <el-table-column prop="id" label="ID" sortable="custom"> </el-table-column> <el-table-column prop="title" label="Title" sortable="custom"> </el-table-column> </el-table-column></data-tables> </template> <script> import axios from 'axios' export default { data() { return { tableData: [], filteredData: [], paginationDef: { pageSize: 10, pageSizes: [10, 20, 50, 100], }, searchDef: { props: ['title', 'id'] }, multipleSelection: [] } }, mounted() { axios.post('select.py', { table: 'master', where: [ { hidden: 0, deal_website: 'dailysteals' } ] }) .then(response => { this.tableData = response.data }) .catch(function (error) { console.log(error); }); }, methods: { handleFilteredData(filteredData) { this.filteredData = filteredData }, hideFilteredData(){ this.filteredData.forEach(function(item){ console.log('ID: ' + item.title); }) }, handleSelectionChange(val) { this.multipleSelection = val; }, hideSelectionData(){ this.multipleSelection.forEach(function(item){ console.log(item.id) }) } } } </script>
Categories: Software

vuejs with select 2 control missing

Vuejs - Wed, 2017-09-13 20:51

I have a very simple Vue js setup that I am trying to used to bind a select2 using a directive. I would rather use a template but for reasons beyond my control I am actual forced to use an asp:DropDownList which means I am forced to have my select boxes inline on the client side.

So I am attempting to set up a Vue.directive but after executing the directive, the select2 is not anywhere to be found. Because the select2 was executed, the original select box get hidden and I end up with nothing showing on the page.

debugging stops are being hit and there are not errors being displayed in the console.

<div id="tabUserInfo"> <input id="myid" type="text" required="required" ref="myid" v-model="firstName" /> <span>{{firstName}}</span> <select id="sel" v-select2="''" v-model="optid"> <option value="1">1</option> <option value="2">2</option> </select> </div><script type="text/javascript"> $(document).ready(function () { Vue.directive('select2', { bind: function (elem, fieldName) { $(elem).select2(); debugger; }, unbind: function (elem) { debugger; } }); var me = "Scott"; var vm = new Vue({ el: '#tabUserInfo', data: { firstName: 'Scott', optid:2 }, }); }); </script>
Categories: Software

These dependencies were not found error in Vue.js

Vuejs - Wed, 2017-09-13 19:03

After updating npm & node to their last versions, I get following errors when I try to run my vue project:

These dependencies were not found:

  • !!vue-style-loader!css-loader!../../../../../../../../../swlkagenda/1.2.0/build/node_modules/vue-loader/lib/style-rewriter?id=data-v-c906422a&scoped=true!wisaapp/login/login.css in /home/projects/wisaweb/trunk/app/modules/wisaapp/login/login.vue

I get same errors for all of my vue files, which all look like as follows:

Login.vue:

<template src="wisaapp/login/login.html"></template> <script src="wisaapp/login/login.js"></script> <style src="wisaapp/login/login.css" scoped></style>

The first error message I wrote was for referred css files in vue file. For js files I get the following error:

  • !!babel-loader!wisaapp/login/login.js in /home/projects/wisaweb/trunk/app/modules/wisaapp/login/login.vue

The path for .js and .css files were before relative but it didn't make any difference.

What can be wrong?

Here is my package.json:

{ "name" : "swllagenda", "version" : "1.0.0", "description" : "Agenda voor Leerlingen die de gegevens van de Schoolware agenda toont.", "author" : "hedwig.theunis@wisa.be", "private" : true, "scripts" : { "dev" : "node build\/dev-server.js", "build" : "node build\/build.js", "unit" : "cross-env BABEL_ENV=test karma start test\/unit\/karma.conf.js --single-run", "e2e" : "node test\/e2e\/runner.js", "test" : "npm run unit && npm run e2e", "lint" : "eslint --ext .js,.vue src test\/unit\/specs test\/e2e\/specs" }, "dependencies" : { "axios" : "^0.15.3", "vue-axios" : "^1.2.2", "lodash" : "^4.17.4", "uglify-js" : "git+https:\/\/github.com\/mishoo\/UglifyJS2.git#harmony", "vue" : "^2.1.10", "vue-router" : "^2.2.0", "vue-style-loader" : "^2.0.4", "vue-touch" : "^2.0.0-beta.4", "vuex" : "^2.1.2", "wisaapp" : "./../../../../wisaweb_trunk/app/modules/wisaapp", "wisaapp-agenda-common" : "./../../../../wisaweb_trunk/app/modules/wisaapp-agenda-common" }, "devDependencies" : { "autoprefixer" : "^6.7.2", "babel-core" : "^6.22.1", "babel-eslint" : "^7.1.1", "babel-loader" : "^6.2.10", "babel-plugin-transform-runtime" : "^6.22.0", "babel-preset-es2015" : "^6.22.0", "babel-preset-stage-2" : "^6.22.0", "babel-register" : "^6.22.0", "chalk" : "^1.1.3", "connect-history-api-fallback" : "^1.3.0", "css-loader" : "^0.26.1", "eslint" : "^3.14.1", "eslint-friendly-formatter" : "^2.0.7", "eslint-loader" : "^1.6.1", "eslint-plugin-html" : "^2.0.0", "eslint-config-standard" : "^6.2.1", "eslint-plugin-promise" : "^3.4.0", "eslint-plugin-standard" : "^2.0.1", "eventsource-polyfill" : "^0.9.6", "express" : "^4.14.1", "extract-text-webpack-plugin" : "^2.0.0-rc.2", "file-loader" : "^0.10.0", "friendly-errors-webpack-plugin" : "^1.1.3", "function-bind" : "^1.1.0", "html-webpack-plugin" : "^2.28.0", "http-proxy-middleware" : "^0.17.3", "webpack-bundle-analyzer" : "^2.2.1", "cross-env" : "^3.1.4", "karma" : "^1.4.1", "karma-coverage" : "^1.1.1", "karma-mocha" : "^1.3.0", "karma-phantomjs-launcher" : "^1.0.2", "karma-sinon-chai" : "^1.2.4", "karma-sourcemap-loader" : "^0.3.7", "karma-spec-reporter" : "0.0.26", "karma-webpack" : "^2.0.2", "lolex" : "^1.5.2", "mocha" : "^3.2.0", "chai" : "^3.5.0", "sinon" : "^1.17.7", "sinon-chai" : "^2.8.0", "inject-loader" : "^2.0.1", "babel-plugin-istanbul" : "^3.1.2", "phantomjs-prebuilt" : "^2.1.14", "chromedriver" : "^2.27.2", "cross-spawn" : "^5.0.1", "nightwatch" : "^0.9.12", "selenium-server" : "^3.0.1", "semver" : "^5.3.0", "opn" : "^4.0.2", "ora" : "^1.1.0", "shelljs" : "^0.7.6", "url-loader" : "^0.5.7", "vue-loader" : "^10.3.0", "vue-style-loader" : "^2.0.0", "vue-template-compiler" : "^2.1.10", "webpack" : "^2.2.1", "webpack-dev-middleware" : "^1.10.0", "webpack-hot-middleware" : "^2.16.1", "webpack-merge" : "^2.6.1", "transfer-webpack-plugin" : "^0.1.4" }, "engines" : { "node" : ">= 4.0.0", "npm" : ">= 3.0.0" } }

npm version : 5.4.1

nodejs version: 0.10.25

Categories: Software

Vue Component Fail to render in blade.php

Vuejs - Wed, 2017-09-13 18:19

I'm new in vuejs and laravel so many thing i am not familiar with. Anyway, this is my code

component.vue

<template> <div class="panel-heading">NewComponent</div> </template> <script> export default { name: 'component', components: { component }, mounted() { console.log('Component mounted.') } } </script>

app.js

require('spark-bootstrap'); require('./components/bootstrap'); import component from './components/component.vue'; Vue.component('component', { template: '<div>Your HTML here</div>', data: function() { return { interval: 0, exposure: 0, clicks: 0, total: 0, cpc: 0 } }, var app = new Vue({ el: '#app', data: { message: 'hello world' }, mixins: [require('spark')] });

home.blade.php

<div id="app"> <component></component> </div>

I google many solutions but none of it is working. Is there anything wrong in my code? The error I get is this:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Categories: Software

Vue CLI - How to have components on multiple pages (Flask)

Vuejs - Wed, 2017-09-13 18:06

I have a NON spa application with pages served by python flask. I am trying to move to using vuecli so that i can get the benefits of ES6. What i thought i would need to do is in the master.jinja2 template i would just wrap the entire thing in . Then i would create components and on the pages where i need those components i could just do .

What's happening instead is the entire app disappears on page render.

How i can i prevent the global Vue instance created by cli in master.js from replacing all content and only load the components when they are on the page.

Thanks not new to vue but i have done everything with include js files is es5 prior to this so its a bit different i think i am just missing something basic to get this to work.

If there is a better way to get what i am after please let me know. If this is in the wrong place please point me to the correct place.

Categories: Software

Bottom to top layout desing for chat application

Vuejs - Wed, 2017-09-13 17:51

I am designing a webapp for chat application. I have an API which returns a list of messages:

chatsite.com/api/thread/1/messages/ [ { "id": 2, "sender": { "id": 2, "email": "usertwo@gmail.com" }, "sent_datetime": "2017-09-06T17:31:30Z", "body": "user two sending a message in new thread (pk1)" }, { "id": 1, "sender": { "id": 1, "email": "user@gmail.com" }, "sent_datetime": "2017-09-06T17:28:56Z", "body": "Nwe thread est body" } ]

This is how the html is layout for now:

<div id="Thread"> <div id="Header"></div> <div id="MessageList"> <div class="message"> <p>{{message.body}}</p> </div> <div class="message"> <p>{{message.body}}</p> </div> <div class="message"> <p>{{message.body}}</p> </div> </div> <div id="Footer"></div> </div>

And its related css:

#Thread { background-color: mediumseagreen; display: flex; flex-direction: column; overflow-y: hidden; height: 600px; } #Header { height: 100px; background-color: blueviolet; } #MessageList { background-color: deepskyblue; height: 100%; display: flex; flex-direction: column; overflow-y: auto; } .message { background-color: white; padding: 8px; border: 1px solid #f9f9f9; font-size: 30px; margin: 4px; } #Footer { height: 100px; background: red; }

As of now all, the messages are ordered by the latest message in a Top to Bottom fashion. Latest being on the top, and so on :

__________________ | | | HEADER | |________________| | | | Latest msg | |________________| | | | 2nd latest msg | |________________| | | | | | | | | |________________| | | | FOOTER | |________________|

But I would like to get the messages in Bottom to Top way like all the messaging platform are these days. Latest being on the bottom an so on:

__________________ | | | HEADER | |________________| | | | | | | | | |________________| | | | 2nd latest msg | |________________| | | | Latest msg | |________________| | | | FOOTER | |________________|

If it helps, I am using Vuejs as the frontend framework.

Categories: Software

Custom Vue directive to omit tag but render tag's contents?

Vuejs - Wed, 2017-09-13 17:43

I'd like to create a custom Vue directive to omit the tag but render the tag's contents when the directive is true.

So for example, if the data for my vue instance is defined as

data:{ omitIt: true }

And if the markup looks like this:

<div v-omit="omitIt" class="someClass"> Hello world! </div>

When omitIt is set to false as it is above, I'd like the following rendered into the dom:

<div class="someClass"> Hello world! </div>

But when omitIt is true I'd like only the following rendered into the dom:

Hello world!

I initially tried to solve this by doing the following (admittedly not a custom vue directive):

<template v-if="!omitIt"> <div class="someClass"> </template> Hello world! <template v-if="!omitIt"> </div> </template>

The above isn't pretty but I thought perhaps it would work. But alas what gets rendered into the dom when omitIt is false is:

<div class="someClass"></div> Hello world!

Any suggestions on how to achieve the results I'm looking for?

Categories: Software

How can I reset/erase a vuex store data?

Vuejs - Wed, 2017-09-13 17:32

In my /src/store/ folder I have actions.js, index.js, mutations.js and state.js which contain the following info

actions.js

export default {}

index.js

import Vue from 'vue' import Vuex from 'vuex' import state from './state' import actions from './actions' import mutations from './mutations' Vue.use(Vuex) export default new Vuex.Store({ state, actions, mutations })

mutations.js

export default { TOGGLE_LOADING (state) { state.callingAPI = !state.callingAPI }, TOGGLE_SEARCHING (state) { state.searching = (state.searching === '') ? 'loading' : '' }, SET_USER (state, user) { state.user = user }, SET_TOKEN (state, token) { state.token = token } }

and state.js

export default { callingAPI: false, searching: '', serverURI: 'http://10.110.1.136:8080', user: null, token: null, userInfo: { messages: [{1: 'test', 2: 'test'}], notifications: [], tasks: [] } }

Now, when a user logs in, I keep the state in as

this.$store.commit('SET_USER', response.data)

Now, when a user logs out, I run my components/logout.vue file in which it has the following code:

export default { data() {}, created() { localStorage.setItem('vuex', null); this.$store.commit('SET_USER', null); window.localStorage.clear(); window.sessionStorage.clear(); } }

But for some reason, the data is somehow persisted.

Categories: Software

Vue resource, using the same form for inserts and updates

Vuejs - Wed, 2017-09-13 17:28

I'm using Vue resource to connect to my backend api. I have a form component which I use for both creating a new resource item and modifying existing resource items. The form works fine, but when I want to save the form, it needs to use the proper http method for the api call. If I am creating a new item, it should use the POST method, and if I'm updating an existing item it should use the PUT method. Right now, my form save method looks something like this:

if(this.itemId > 0) { // Update existing item myresource.update({id: this.itemId}, this.item).then(response => { //... }, response => { //... }); } else { // Post new item myresource.save({}, this.item).then(response => { //... }, response => { //... }); }

Basically, I have to use an if statement to check whether to use the update or save resource functions, then the success/fail promises both use the same code. Is there some way to combine the two methods above with something like this:

var method = this.itemId ? 'PUT' : 'POST'; myresource.request(method, {id: this.itemId}, this.item).then(response => { //... }, response => { //... });

The above code obviously doesn't work, but is there a similar way to accomplish this without using an if statement and repeating my success/fail promises for each request type?

Categories: Software

Multiple vue files on the same element and Vuex state(Vuex + Vue.js + Laravel)

Vuejs - Wed, 2017-09-13 17:27

I have registered a global component in app.js of Laravel called <unread>. In one of my blade files, I created a new Vue instance to handle a functionality that sits on the same #app element.

The problem is that though global component is rendered in this page but vuex state is different from other blade files. My question is if its possible to get around this problem without making a separate component? And if its even valid to follow this approach.

I was not able to find an explanation or solution on this. Please enlighten me. Heres my code.

In app.js,

Vue.component('unread', require('./components/core/Unread.vue')); import { store } from './store' window.onload = function () { const app = new Vue({ el: '#app', store }); }

In blade file,

@section('scripts') <script type="text/javascript"> window.onload = function() { new Vue({ el: '#app', data: { //data here }, //rest of code }); }; </script>

My Unread.vue file,

<template lang="html"> <a href="#"> <span class="badge" style="background-color:red">4</span> </a> </template> <script> export default { mounted() { console.log('mounted') this.get_unread() }, methods: { get_unread() { this.$http.get('/ajax/get-unread') .then((nots) => { nots.body.forEach( (not) => { this.$store.commit('add_not', not) }) }) } } } </script>

Note: I get the mounted console, but this.get_unread() is not sent to update the vuex state

Uncaught (in promise) TypeError: Cannot read property 'commit' of undefined

Categories: Software

How to get golbal data in main.js file in Vue JS?

Vuejs - Wed, 2017-09-13 17:13

following code is from my main.js file. Here I am parsing data from a url using Vue object and it returns some array of data. Now, In the main.js file I have a another GraphChart object and here I need some data from tableData.

How it would be possible? or any other tricks ? Now I am getting nothing.

var tableData = new Vue({ data: { items: '' }, methods: { graphData: function () { var self = this; var testdata= ''; $.get( 'http://localhost:3000/db', function( data ) { self.items = data; }); }, }, created: function() { this.graphData(); }, computed:{ }); new GraphChart('.graph', { stroke: { width: 24, gap: 14 }, animation: { duration: -1, delay: -1 }, // series: needs data from ITEMS object series:items._data.radialChart[1] } )

Categories: Software

VueJS: Can't reach "data" from callback

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

This is the first time I'm using VueJs, so this might be a very basic thing, but in one of my callbacks I try to set a new value to a value, saved in the "data" component.

But whenever I try to run this method, Vue says my "this" is undefined, so I can't set this new value.

export default { name: 'app', data() { return { collection : {}, } }, mounted: function(){ var event = contract.statuschangedEvent(function(error, result) { if (!error){ this.collection[result.args.id].status = result.args.status } }); ...

The "contract" object is a web3 object, and the syntax should be fine according to this documentation

The error I'm getting is "Uncaught TypeError: Cannot read property '[object Object]' of undefined"

Categories: Software

Pages