Software
Vuejs: component aggregation
Starting from the following simple reddit-like example : https://jsfiddle.net/coligo/g7mu5ndz/
Vue.component('post', { template: "#post-template", props: ['post'], data: function () { return { upvoted: false, downvoted: false }; }, methods: { upvote: function () { this.upvoted = !this.upvoted; this.downvoted = false; }, downvote: function () { this.downvoted = !this.downvoted; this.upvoted = false; } }, computed: { votes: function () { if (this.upvoted) { return this.post.votes + 1; } else if (this.downvoted) { return this.post.votes - 1; } else { return this.post.votes; } } } }); var vm = new Vue({ el: "#app", data: { posts: [{ title: "A post for our reddit demo starting at 15 votes", votes: 15 }, { title: "Try out the upvoting, it works, I promise", votes: 53 }, { title: "coligo is the bomb!", votes: 10 }] } });I'd like to :
- a) Display the total number of upvotes (under the list of posts, in the #app div
- b) For each post, display the percentage of total upvotes it has gained
Is this possible without managing each post state in the parent?
Vuejs on IOS wont detect changes when using es6 Proxy instance
Here is my sample code using vuejs 2 framework:
a= {_data:{x: 2}} b = new Proxy(a, { get(target, name){ if(name !== '_data') return target._data[name] return target._data; }, set(target, name, value){ if(name !== '_data') target._data[name] = value else target[name] = value; return true; } }) v = new Vue({ el: '#app', data:{ c: b } });It works properly on Chrome an Firefox both in android and desktop version, But when I run it on IOS, vue won't detect changes of data. Is this because of IOS support of ES6 Proxy??
Here is a jsfiddle link of above sample code: https://jsfiddle.net/aminfa92/j1oxcuLq/
How can I use Blade in Vue files?
I'm trying to use Blade in my Vue file carousel-signUp.vue
Like:
<template> <div> <form action="{{route('dump')}}" method="POST" > /* Some code here...*/ </form> </div> </template>But in the end I'm getting an error.
The compiler can't understand the difference between Vue syntax and Blade syntax. How can I define Blade syntax in Vue files?
Or, does anyone have an idea how to use {{route('dump')}} value in my vue file?
for loop through array and bind class to element class attribute in vuejs
I am trying to bind classnames into the class attribute with vuejs looping through an array like this:
Here I pass the method call in a :class="paymentTypeClass(value)" to bind to the vue template like so:
<li v-for="card in paymentType" class="o-pf-list__item" :class="paymentTypeClass(value)"> {{ card }} </li> new Vue ({ el: '#app', data: { paymentType: ['paymentType1', 'paymentType2', 'paymentType3', 'paymentType4', 'paymentType5'] }, methods: { functionName: function(value) { var i = 0; for (i in this.paymentType) { value = 'o-pf-list__item--' + this.paymentType[i]; } return value + ' pull-left'; } } });The result is that it only prints out the last index value in the array so it is actually overwriting. Why is this? Please help.
Logs in the console:
o-pf-list__item--bitcoin app.js:51663 o-pf-list__item--credit app.js:51663 o-pf-list__item--debitcard app.js:51663 o-pf-list__item--eft app.js:51663 o-pf-list__item--masterpass app.js:51663 o-pf-list__item--bitcoin app.js:51663 o-pf-list__item--credit app.js:51663 o-pf-list__item--debitcard app.js:51663 o-pf-list__item--eft app.js:51663 o-pf-list__item--masterpass app.js:51663 o-pf-list__item--bitcoin app.js:51663 o-pf-list__item--credit app.js:51663 o-pf-list__item--debitcard app.js:51663 o-pf-list__item--eft app.js:51663 o-pf-list__item--masterpass app.js:51663 o-pf-list__item--bitcoin app.js:51663 o-pf-list__item--credit app.js:51663 o-pf-list__item--debitcard app.js:51663 o-pf-list__item--eft app.js:51663 o-pf-list__item--masterpass app.js:51663 o-pf-list__item--bitcoin app.js:51663 o-pf-list__item--credit app.js:51663 o-pf-list__item--debitcard app.js:51663 o-pf-list__item--eft app.js:51663 o-pf-list__item--masterpassRails System Test Not Loading Vue
I have a Vue feature in my rails 5.1 app that basically accepts a deeply nested form. The feature works perfectly in development, staging and production, however, when using the new minitest system tests with selenium and capybara, vue doesn't appear to load. As Selenium shows you whats happening in real time, I can see that the rails elements (such as _header, _footer, h1-Title) are all loading fine, but the Vue piece never appears.
Here is my testing setup:
Gemfile
group :test do gem 'minitest-rails' gem 'minitest-reporters' gem 'minitest-rails-capybara' gem 'faker' gem 'capybara', '~> 2.7', '>= 2.7.1' gem 'selenium-webdriver' gem 'simplecov', :require => false endtest/test_helper.rb
ENV["RAILS_ENV"] = "test" require 'simplecov' SimpleCov.start 'rails' require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" require "minitest/rails" require "minitest/rails/capybara" require "minitest/pride" require 'minitest/reporters' require "support/test_password_helper" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new ActiveRecord::FixtureSet.context_class.send :include, TestPasswordHelper class ActiveSupport::TestCase require "#{Rails.root}/db/seeds.rb" fixtures :all require 'minitest/autorun' include TestPasswordHelper # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # Add more helper methods to be used by all tests here... def sign_in(user) post user_session_path \ 'user[email]' => user.email, 'user[password]' => user.password end def submit_form find('input[name="commit"]').click end endtest/application_system_test_case.rb
require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] include Devise::Test::IntegrationHelpers endtest/system/proposals_test.rb
require "application_system_test_case" class ProposalsTest < ApplicationSystemTestCase test 'create a proposal' do sign_in users(:martin) @supplier = businesses(:supplier_two) @project = projects(:pete_project_three) visit dashboard_path assert_selector 'h3', text: @supplier.display_name assert_link text: 'Propose for project' click_on 'Create Proposal' assert_selector 'h1', text: 'New Proposal' assert_selector 'small', text: '(Version: 1)' fill_in 'title0', with: 'This is a title' fill_in 'body0', with: 'This is a body' click_on 'Add Section' fill_in 'title1', with: 'This is a second title' fill_in 'body1', with: 'This is a second body' end endThe test itself is failing at fill_in 'title0', with: 'This is a title' because the vue feature doesn't load
Note I am using turbolinks, but as mentioned, it's all working perfecting in practice, its just not loading for the system tests.
Happy to provide more detail if needed
Loading single file components in MVC5 using webpack
I have a MVC solution in VS2015 in wich I use vue.js to bind data, I tried to use webpack to use single file components with extension .vue.
On first instance I tried to generate 1 file.js foreach file.vue with this config:
const fs = require("fs"); const path = require("path"); // build an object that looks like // { // "filename": "./filename.vue" // } // to list the entry points for webpack to compile. function buildEntry() { const reducer = (entry, file) => { entry[file.split(".").shift()] = `./Vue/${file}`; return entry; }; return fs.readdirSync(path.join(__dirname, "Vue")) .filter(file => file.endsWith(".vue")) .reduce(reducer, {}); } module.exports = { entry: buildEntry(), output: { path: path.join(__dirname, "Vue"), filename: "[name].js", library: "[name]" }, module: { loaders: [ { test: /\.vue$/, loader: 'vue-loader' }, ], } }So I could use a new component like this:
Vue.component("foo", foo);But that generates to much .js files and it's dificult to maintain so I tried to unify them with this config:
module.exports = { entry: "./Vue/BundleIndex.js", output: { path: __dirname, filename: "./Vue/bundle.js", }, module: { loaders: [ { test: /\.vue$/, loader: 'vue-loader' }, ], } }with this bundleIndex.js :
import foo from '.\\foo.vue' import example from '.\\example.vue'I tried to use components as I used to, but I can't. what I'm missing here?
Accessing _this
I have a typescript file... and it's failing TSLint. Was hoping someone could answer this.
So the object looks something like this:
export default class Container extends Vue { // methods doSomething() { console.log('something happened') } items: object[] = [ { title: test, onclick: _this.doSomething(); } ] }I tried using this instead of _this, but this only refers to the individual object in items. So then I found in Chrome dev tools that I can use _this to access the containing class. However, when I put this code thru TSLint, it complains that it cannot find the name '_this'.
My project uses tslint-config-airbnb.
Thanks. John.
What decides the directives bind sequences in Vue.js 1.0?
What's the custom directives bind sequences in Vue.js 1.0? Why the console.log result is :
bind loading
bind load
bind calendar
bind filterpanel
bind footprint
Code example is here:
// HTML <!-- Directives--> <div v-mask="UI.showMask"></div> <div v-loading="UI.showLoading"></div> <div v-load = "request.isLoadData"></div> <div v-calendar = "pageParams.leaveDate"></div> <div v-footprint = "UI.footprint"></div> // js Vue.directive('calendar', { bind: function () { console.log('bind calendar') // ... } }); Vue.directive('mask', { bind: function () { console.log('bind mask') // ... } }); Vue.directive('loading', { bind: function () { console.log('bind loading') // ... } }); Vue.directive('load', { bind: function () { console.log('bind load') // ... } update: function () { // send Query ... } }); Vue.directive('footprint', { bind: function () { console.log('bind footprint') // ... } });Vue.js nextTick inside computed property
I have "context menu" component. Computed properties top and left define menu position using $event property. But when I trying to open context menu, menu element is not rendered yet and top cannot be calculated without menu's offsetHeight, so I figured out to use some "nextTick hack" inside computed property:
top() { if (!this.menuIsRendered) { // by default, menuIsRendered is false this.$nextTick(() => { this.menuIsRendered = true }) return 0 } ... // menu element is rendered, calculate top value },Is this ok? I think there must be a better way to do this.
Also, full component code:
<template> <div ref="menu" :style="{top: `${top}px`, left: `${left}px`}" v-click-outside="close" @contextmenu.prevent v-if="show"> <slot></slot> </div> </template> <script> export default { props: [ 'show', 'event' ], data() { return { menuIsRendered: null, } }, computed: { top() { if (!this.menuIsRendered) { this.$nextTick(() => { this.menuIsRendered = true }) return 0 } let top = this.event.y let largestHeight = window.innerHeight - this.$refs.menu.offsetHeight - 25 return top > largestHeight ? largestHeight : top + 1 }, left() { if (!this.menuIsRendered) { return 0 } let left = this.event.x let largestWidth = window.innerWidth - this.$refs.menu.offsetWidth - 25 return left > largestWidth ? largestWidth : left + 1 }, }, methods: { close() { this.$emit('close') }, } } </script>Component usage:
<context-menu @close="close" :event="event" :show="show"> <div @click="doAction">Action</div> <div @click="doAnotherAction">Another action</div> </context-menu>In Framework7 Vue, is it possible to create a sortable list that is activated by tap and hold?
Tapping and holding to reorder list items is a common interface pattern in apps now.
Is there anyway to create a sortable list in this way in Framework7 Vue?
I'm currently using SortableJS / Vue Draggable to accomplish this, but the animation is not quite as slick as the sortable that is built into Framework7.
Please see this video of my current implementation to understand what I mean
60,000,000 Clicks for Copyright Reform
60,000,000 digital flyers.
117,000 activists.
12,000 tweets to Members of the European Parliament (MEPs).
Europe has been Paperstormed.

Earlier this year, Mozilla and our friends at Moniker launched Paperstorm.it, a digital advocacy tool that urges EU policymakers to update copyright laws for the Internet age.
Paperstorm.it users drop digital flyers onto maps of European landmarks, like the Eiffel Tower and the Reichstag Building in Berlin. When users drop a certain amount, they trigger impassioned tweets to European lawmakers:

“We built Paperstorm as a fun (and mildly addictive) way for Internet users to learn about and engage with a serious issue: the EU’s outdated copyright laws,” says Mozilla’s Brett Gaylor, one of Paperstorm’s creators.
“The Parliament has a unique opportunity to reform copyright,” says Raegan MacDonald, Mozilla’s Senior EU Policy Manager. “We hope this campaign served as a reminder that EU citizens want a modern framework that will promote — not hinder — innovation and creativity online. The success of this reform hinges on whether the interests of these citizens — whether creators, innovators, teachers, librarians, or anyone who uses the internet — are truly taken into account in the negotiations.”
Currently, lawmakers are crafting amendments to the proposal for a new copyright law, a process that will end this year. Now is the time to make an impact. And we are.
Over the last two months, more than 100,000 Internet users visited Paperstorm.it. They sent 12,000 tweets to key MEPs, like France’s Jean-Marie Cavada, Germany’s Angelika Niebler, and Lithuania’s Antanas Guoga. In total, Paperstormers contacted 13 MEPs in 10 countries: Austria, France, Germany, Italy, Lithuania, Malta, Poland, Romania, Sweden and the UK.
Then, we created custom MEP figurines inside Paperstorm snowglobes. A Mozilla community member from Italy hand-delivered these snowglobes right to MEPs offices in Brussels, alongside a letter urging a balanced copyright reform for the digital age. Here’s the proof:

Angelika Niebler, Member, ITRE (left) and Jean-Marie Cavada, Vice-Chair, JURI

JURI Committee Vice-Chair, MEP Laura Ferrara, Italy (center) with Mozilla’s Raegan MacDonald and Edoardo Viola
Thanks for clicking. We’re looking forward to what’s ahead: 100,000,000 clicks—and common-sense copyright laws for the Internet age.
The post 60,000,000 Clicks for Copyright Reform appeared first on The Mozilla Blog.
Vue.js methods vs computed properties. How they interact with the DOM
I am trying to figure out when to call the methods property, versus when is best to call a computed property. It seems to me that computed is generally preferable since a method will respond anytime a property is called which accesses the DOM.
In the following code, the two buttons tracks a basic counter which increments by 1. The same output is passed to the DOM through a method and through a computed property. Every increment triggers both the computed and the methods properties as shown in the console.
<div id="content"> <!--counter control--> <button v-on:click="counter++">Increase Counter</button> <button v-on:click="counter--">Decrease Counter</button> <!--counter output--> <p>{{counter}}</p> <p>{{ resultMethod() }}</p> <p>{{ resultComputed }}</p> </div> <script> new Vue({ el: '#content', data: { counter: 0 }, computed: { resultComputed: function(){ console.log("computed.result was run"); return this.counter < 5 ? 'small_number' : 'LARGENUMBER'; } }, methods: { resultMethod: function(){ console.log("methods.result was run"); return this.counter < 5 ? 'small_number' : 'LARGENUMBER'; } } }) </script>Now if we add another couple data properties we can see that tracking them doesn't cause the method or the computed property to be triggered.
<!--new data options--> <button v-on:click="secondCounter++">Second Counter</button> <button v-on:click="formSubmit=true">Form Submit</button> //New Data Properties secondCounter: 0, formSubmit: falseNow displaying these data properties to the DOM shows first that the data is indeed being tracked correctly, and second these actions trigger the same methods property as our counter even though these variables are not related to this method.
<p>{{secondCounter}}</p> <p>{{formSubmit}}</p>Finally, if we create an entirely random and unrelated method and reference it in the DOM, this too will be called everytime any of our variables are changed from the DOM. I use the simple method as an example.
<h2>{{ unrelatedMethod() }}</h2> unrelatedMethod: function(){ console.log("We are now using another random method"); var number = 2000; return number; }So what exactly is happening here behind the scenes? Does Vue have to run every related property everytime the DOM is updataed? When would methods be a better choice over computed properties?
vue js passing "top-level" Boolean not working, only nested
This is weird. When I define the Boolean property showModal at the top level it is simply being ignored by vue.js. Here's what I am doing:
//Component: export default { props:['rating', 'showModal'], data: function data () { return { rating: this.rating, showModal: this.showModal }; } };Invoking the view:
const sharedRating = { title: '', remark: '' }; let showModal = false; new Vue({ el: '#rating-edit-container', data: { showModal: showModal, rating: sharedRating } }); showModal = true;Then both values are being passed to the component:
<rating-edit :rating="rating" :show-modal="showModal"></rating-edit>But when I change the value of showModal nothing happens.
If I pass showModal inside the rating object and use that nested property everything works fine:
const sharedRating = { showModal: false, title: '', remark: '' }; new Vue({ el: '#rating-edit-container', data: { rating: sharedRating } }); sharedRating.showModal = true;Shouldn't "stand alone" boolean properties also be working in Vue or do they always need to be "wrapped"?
Vue Router with Render Template
I'm a beginner used vue js. I tried vue router to navigation in my page. Everything went smoothly and easily. But I have a problem, when navigation need template to show page corresponding. Actually, I want my script neatly organized by splitting the file. Such as rooting itself , .html itself, etc. This is my script :
Route.js
/* Configuration Routing */ //const Home = { template: 'templates/home.html' }; const Thread = { template: '<div>THREAD</div>' }; const Tag = { template: '<div>TAG</div>' }; const TrendingTag = { template: '<div>TRENDING TAG</div>' }; const Category = { template: '<div>CATEGORY</div>' }; const User = { template: '<div>USER</div>' }; const Home = Vue.component('home', function(resolve) { $.get('templates/home.html').done(function(template) { resolve({ template: template, data: function () { return { message: 'Welcome' }; } }); }); }); //const Home = Vue.component('home', require('assets/js/controllers/home.js')); const routes = [ { path: '/', component: Home }, { path: '/thread', component: Thread }, { path: '/tag', component: Tag }, { path: '/trending-tag', component: TrendingTag }, { path: '/category', component: Category }, { path: '/user', component: User } ]; const router = new VueRouter({ mode: 'history', routes }); const app = new Vue({ router }).$mount('#app');In this case, actually const home must exist in another file. Like home.js. Because I have to create data in home.js.
Home.js
Vue.component('homepage', function(resolve) { $.get('templates/home.html').done(function(template) { resolve({ template: template, data: function () { return { message: 'Welcome' }; } }); }); });home.html
<div id="homepage"> <template id="home"> <h3 class="page-title" id="content"> {{ message }} </h3> </template> </div>Can you help me please ? I really stuck with this case. Thank you.
Force refresh of an affix in Vue
I am using a bootstrap affix within a Vue JS page. When I first navigate to the route containing the affix (the affix visibility is controlled via v-if), it works perfectly with scrolling. However, when I navigate away from that route and then back again, the affix is broken: it is stuck at the top of the page and doesn't scroll.
I have found online that, were I using jquery, I could call $('#affix').affix('checkPosition') to force the affix to reposition (but I don't have access to jquery).
I suspect the issue is that Vue is creating the affix on the first load, and then caches the same DOM object to be used later. But when it is re-inserted into the page, bootstrap is no longer aware of it and the affixing behavior breaks.
At this point, I think I have a few options, any of which would solve this problem:
- Is there a smart way to call Jquery from within a Vue component? I'm not using Jquery anywhere else, so would rather not.
- Is there a way to force Bootstrap affixes to refresh?
- Is there a way to force Vue to not cache this component, creating a new one every load?
- Is there a better way of creating an affix with Vue?
Thanks!
Here is the Vue component of concern:
<template> <div id="funclist-affix" class="panel panel-default" data-spy="affix" data-offset-top="155"> <div class="panel-body"> <h4>Functions</h4> <div class="list-group function-list"> <router-link v-for="(func,line) in functions" :key="line" :to="'#' + func.name" :class="['list-group-item', 'code', {uncovered: func.uncovered}]" :title="func.name">{{ func.name }}</router-link> </div> </div> </div> </template> <script> export default { name: 'functionList', data () { return { } }, props: ['functions'] } </script> <style> a { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } #funclist-affix { max-height: calc(100% - 2 * 20px); overflow-y: auto; } </style>Editing record within list, with dynamically defining children properties with VueJS
With VueJS, I am trying to create a generic component that would work with different types of records.
For instance, let's say I have user records:
var users = [ { UserID: 1, username: "pan",email:"peter.pan@neverland.com" }, { UserID: 2, username: "john",email:"john.doe@somewhere.com" } ];And group records
var groups = [ { GroupId: 1, groupName: "Users", description: "Lorem ipsum ..." }, { GroupId: 2, groupName: "Admins", description: "Some people with super powers" } ];I want to create a Vue component to edit those records, so it can be defined as such:
<record-editor v-bind:record="user[0]" title="Edit user"> <text-editor label="User name" property="username"></text-editor> <text-editor label="Email" property="email"></text-editor> </record-editor> <!-- For the binding syntax, I am not sure what should I use to bind to a record in the lists shown before --> <record-editor v-bind:record="groups[0]" title="Edit group"> <text-editor label="groupName" property="groupName"></text-editor> <text-editor label="Description" property="description"></text-editor> </record-editor>Right now, what I have is:
(function() { var textEditor = Vue.component('text-editor', { template: "#text-editor", props: ['label', 'property'] }); var recordEditor= Vue.component('record-editor', { template: '#model-editor', props: ['title', 'record'] }); var vue = new Vue({ el:"#someContainer", data: { users : users, groups: groups } }) }()) <template id="text-editor"> <div> <label v-bind:for="property">{{label}}</label> <!-- need help figuring what to put in v-bind:value --> <input type="text" v-bind:name="property" v-bind:id="property" v-bind:value=""> </div> </template> <template id="record-editor"> <div> <h2>{{title}}</h2> <form> <slot></slot> </form> </div> </template>So basically, what I am missing is how to bin to the elements in the list to edit them.
And how can I dynamically define properties for the sub components (text-editor).
Passing props with programmatic navigation Vue.js
I have a Vue component that has a prop named 'title' e.g:
<script> export default { props: ['title'], data() { return { } } } </script>I navigate to the component programmatically after a certain action is complete. Is there a way to programmatically route a user while also setting the prop value? I know you can create a link like this:
<router-link to="/foo" title="example title">link</router-link>However, is there a way to do something like the following?
this.$router.push({ path: '/foo', title: 'test title' })EDIT:
As suggested I've changed my route to the following:
{ path: '/i/:imageID', component: Image, props: true }And the navigation to the following:
this.$router.push({ path: '/i/15', params: {title: 'test title' }})However, my Image component (template - see below) still doesn't show any title.
<h1>{{ title}}</h1>Is there anything that could be causing issues?
Pass value from a component to the parent instance
I have a component named cartComponent with a data property cartCount that gets incremented whenever a new item is added to the cart.
I need to use that value to update the value in the template which is not a part of the component. Is this possible?
Here's is the script for my parent Vue instance:
new Vue({ el: "#cart-app", components: { cart: cartComponent }, data: { searchQuery: '', appliedFilters: ['Day 1'], purchaseData: json, cCount: 0 // CARTCOUNT; NEEDS TO BE UPDATED FROM COMPONENT } });Defending Net Neutrality: Millions Rally to Save the Internet, Again
We’re fighting for net neutrality, again, because it is crucial to the future of the internet. Net neutrality serves to enable free speech, competition, innovation and user choice online.
On July 12, it was great to see such a diversity of voices speak up and join together to support a neutral internet. We need to protect the internet as a shared global public resource for us all. This Day of Action makes it clear, yet again, that net neutrality it a mainstream issue, which the majority of Americans (76% from our recent survey) care about and support.
We were happy to see a lot of engagement with our Day of Action activities:
- Mozilla collected more than 30,000 public comments on July 12 alone — bringing our total number of public comments to more than 75,000. We’ll be sharing these with the FCC
- Our nine hour Soothing Sounds of Activism: Net Neutrality video, along with interviews from Senators Al Franken and Ron Wyden, received tens of thousands of views
- The net neutrality public comments displayed on the U.S. Firefox snippet made 6.8 million impressions
- 30,000 listeners tuned in for the net neutrality episode of our IRL podcast
The Day of Action was timed a few days before the first deadline for comments to the FCC on the proposed rollback of existing net neutrality protections. This is just the first step though. Mozilla takes action to protect net neutrality every day, because it’s obviously not a one day battle.
Net neutrality is not the sole responsibility any one company, individual or political party. We need to join together because the fight for net neutrality impacts the future of the internet and everyone who uses it.
What’s Next?
Right now, we’re finishing our FCC comments to submit on July 17. Next, we’ll continue to advocate for enforceable net neutrality through all FCC deadlines and we’ll defend the open internet, just like we did with our comments and efforts to protect net neutrality in 2010 and 2014.
The post Defending Net Neutrality: Millions Rally to Save the Internet, Again appeared first on The Mozilla Blog.

