link959 link960 link961 link962 link963 link964 link965 link966 link967 link968 link969 link970 link971 link972 link973 link974 link975 link976 link977 link978 link979 link980 link981 link982 link983 link984 link985 link986 link987 link988 link989 link990 link991 link992 link993 link994 link995 link996 link997 link998 link999 link1000 link1001 link1002 link1003 link1004 link1005 link1006 link1007 link1008 link1009 link1010 link1011 link1012 link1013 link1014 link1015 link1016 link1017 link1018 link1019 link1020 link1021 link1022 link1023 link1024 link1025 link1026 link1027 link1028 link1029 link1030 link1031 link1032 link1033 link1034 link1035 link1036 link1037 link1038 link1039 link1040 link1041 link1042 link1043 link1044 link1045 link1046 link1047 link1048 link1049 link1050 link1051 link1052 link1053 link1054 link1055 link1056 link1057 link1058 link1059 link1060 link1061 link1062 link1063 link1064 link1065 link1066 link1067 link1068 link1069 link1070 link1071 link1072 link1073 link1074 link1075 link1076 link1077 link1078 link1079 link1080 link1081 link1082 link1083 link1084 link1085 link1086 link1087 link1088 link1089 link1090 link1091 link1092 link1093 link1094 link1095

[Vue.js] Conditional image source with Vue based on boolean value Subscribe to RSS

I currently have my image tag set up like so:

<img v-if=”highQuality” :src=”post.data.url”>
<img v-if=”highQuality == false” :src=”post.data.thumbnail”>

As you can see the image src changes based on whether highQuality is true or false.

there is a select tag with the two bool options, if I start on false and change it to true it updates the images to high quality sources, but if I set it back to false it seems to stay on High quality. So I’m thinking that this is a bad attempt at a vue.js if conditional.

is there a more “Vue” like way of writing this?

edit: extra code

DOM

<select v-model=”highQuality”>
<option value=”true”>High Quality</option>
<option value=”false”>Low Resolution</option>
</select>

JS

var app = new Vue({
el: ‘#app’,
data: {
highQuality: false,
posts: [],
},
});

Solution :

The problem is the <option>s. <select> is assigning a string, not a boolean.

Don’t use:

<option value=”true”>High Quality</option>

Use:

<option :value=”true”>High Quality</option>

Problematic:

var app = new Vue({
el: ‘#app’,
data: {
highQuality: false,
posts: [],
post: {data: {url: ‘http://bc.id.au/images/fr\_flag.gif', thumbnail: ‘http://bc.id.au/images/de\_flag.gif'}
},
});
<script src=”https://unpkg.com/vue"></script>

<div id=”app”>
<select v-model=”highQuality”>
<option value=”true”>High Quality</option>
<option value=”false”>Low Resolution</option>
</select>

<img v-if=”highQuality” :src=”post.data.url”>
<img v-if=”highQuality == false” :src=”post.data.thumbnail”>
</div>

Fixed:

var app = new Vue({
el: ‘#app’,
data: {
highQuality: false,
posts: [],
post: {data: {url: ‘http://bc.id.au/images/fr\_flag.gif', thumbnail: ‘http://bc.id.au/images/de\_flag.gif'}
},
});
<script src=”https://unpkg.com/vue"></script>

<div id=”app”>
<select v-model=”highQuality”>
<option :value=”true”>High Quality</option>
<option :value=”false”>Low Resolution</option>
</select>

<img v-if=”highQuality” :src=”post.data.url”>
<img v-if=”highQuality == false” :src=”post.data.thumbnail”>
</div>

Solution 2:

Maybe the highQuality == false condition is failing, are you sure you’re setting highQuality to exactly false?

You needn’t duplicate the tag, just do this instead:

<img :src=”highQuality ? post.data.url : post.data.thumbnail”>

[Vue.js] why does element-ui's validate() function keep clearing server side passed validation (via error prop) errors? Subscribe to RSS

when using element-ui form validation for validating simple rules on client side to relieve server from additional load. After the initial client side validation passes, I send them to server and do some more (complex) validations on server side.

This works without any problems when I get the returned errors and display them on custom built error fields. But when try to use element-ui’s built in error prop to display the errors within the form-item then after the second submit the server side errors disappear from form-item. Even if I hard code the error prop like error=”This is a error message” the message still disappears after running the validate() method.

here is a sample of the form

<el-form :model=”form” :rules=”rules” ref=”form”>
<el-form-item prop=”mobile_number” :error=”errors.mobile_number[0]“>
<el-input v-model.number=”form.mobile_number”> </el-input>
</el-form-item>
</el-form>

and this is the part where I submit the form

submitForm(){
this.$refs.form.validate((valid) => {
if (valid) {
axios.post(url,
this.form
).then((response) => {
if(response.data.status == ‘success’){
// do stuff when successful
}
}).catch((error) => {
this.errors = error.response.data.errors;
})
}
});
}

When I remove the validate() method or when i disable the validation rules on client side then the server side remain. How can I solve this issue?

Solution :

After looking into the source that is what I found. The element-ui validate uses the same error message variable (validateMessage) for both internal process and external prop errors. So when the validate() runs the element-ui is checking its own rules first and if it passes then returns valid true else it creates error and assigns them to the validateMessage.

In the other hand to pass manual errors element ui is using a watcher that watches the error prop.

watch: {
error: {
immediate: true,
handler: function handler(value) {
this.validateMessage = value;
this.validateState = value ? ‘error’ : ‘’;
}
},
validateStatus: function validateStatus(value) {
this.validateState = value;
}

},

So to take control of what is assigned to the validateMessage the watcher needs to be triggered which can only be when the error prop changes as long as it remains the same the internal validate process will overwrite the validateMessage.

validator.validate(model, { firstFields: true }, function (errors, invalidFields) {
_this.validateState = !errors ? ‘success’ : ‘error’;
_this.validateMessage = errors ? errors[0].message : ‘’;

callback(_this.validateMessage, invalidFields);
_this.elForm && _this.elForm.$emit(‘validate’, _this.prop, !errors, _this.validateMessage || null);
});

In my case, because client side validation passes the rules validateMessage is set to “” so no errors are displayed even if server side still remain errors.

In short, when the elements server side validator passes valid I clear my local errors just before submitting the form. And let it set them again if any exist. And it works.

submitForm(){
this.$refs.form.validate((valid) => {
if (valid) {
this.errors = [];
axios.post(url,
this.form
).then((response) => {
if(response.data.status == ‘success’){
// do stuff when successful
}
}).catch((error) => {
this.errors = error.response.data.errors;
})
}
});
}

[Vue.js] Cypress never reaches step 2 after visit() - stuck in nuxt-loading Subscribe to RSS

the cypress visit function waits for the load event from the page - and that is fired, so cypress goes on with the next step in the test. this of course fails because nuxt is still in the loading state (see link below). and it never gets resolved, even if i keep waiting after the test fails (in the electron browser).

everything works fine if there is another visit call beneath the first one. but thats not really a solution. is anyone else having a similiar problem or had this before?

here a example testrun: https://i.imgur.com/2nHt7RW

Solution :

What do you mean by “kinda fires the load event”?

I guess the similar question has been asked here.
Also, if not done that yet, try to add timeout option to visit() as well.

// Wait 30 seconds for page ‘load’ event
cy.visit(‘/YOUR_PAGE’, { timeout: 30000 })

I’m not sure if any of this helps but I can’t comment yet, so had to post this as an answer.

[Vue.js] How to prevent firebase db access from chrome console or other methods Subscribe to RSS

So there is a single page frontend only app. Right now there is something like this

// db.js
import firebase from “firebase/app”
import “firebase/firestore”;

var firebaseConfig = {

};

export const db = firebase
.initializeApp(firebaseConfig)
.firestore();

in main.js I was experimenting with putting the db instance in the global window scope just to see if I could go to the chrome web console and access it to submit a doc and indeed I can

// main.js
import { db } from ‘./db’
window.db = db;

and then from chrome console

db.collection(“test”).add({‘somekey’: ‘Can I add this doc?’})

How do I prevent someone from doing this without having a real backend to check auth? I like the reactivity of vue.js + firebase. If I don’t expose the db variable to global scope is that enough? I was reading this post:

https://forum.vuejs.org/t/how-to-access-vue-from-chrome-console/3606/2

because any variable you create inside the main.js fiel will still not be globally available due to how webpack

Solution :

One of the great things about Firestore is that you can access it directly from within the web page. That means that within that web page, you must have all configuration data to find the relevant Google servers, and find the Firebase project on those servers. In the example, that data is part of firebaseConfig.

Since you app needs this configuration, any malicious user can also get this data from the app. There is no way to hide this: if you app needs, a sufficiently motivated malicious user will be able to find it. And once someone has the configuration, they can use it to access the database.

The way to control access to the database, is by using Firebase’s server-side security rules. Since these are enforced on the server, there is no way to bypass them, neither by the code, nor by the code that a malicious user writes.

You can use these security rules to ensure that all data is valid, for example making sure that all the required fields are there, and that there’s no data that the app doesn’t use.

But the common approach is to also ensure that all data access is authorized. This requires that the users are authenticated with Firebase Authentication. You can either require the users to sign in with their credentials, or you can anonymously sign them in. In the latter case they don’t need to enter any credentials, but you can still ensure for example that each user can only write data to their own area of the data, and that they can only read their own data.

[Vue.js] is there a way i can style the x and y axis that are in c3.js? Subscribe to RSS

there is this chart that i made with c3.js library that i would like to change the width of the y axis to be much thinner
https://d.pr/free/i/xSbyRB

I tried to add style directly in the class like so but didn’t work

.c3-axis-y path {
stroke-width: 1px;
}

I also wanted to show grids along x axis like mentioned in the documentation but they didn’t show up like expected

grid: {
x: {
show: true
}
}

how can i achieve solving these both issues please ?

Solution :

The stroke is 1px. I wouldn’t make it thinner (as you’ll get mixed results in different browsers). But you can get the same effect if you minimize the contrast, by changing the stroke color:

/* axis line */
.c3 .domain {
stroke: #eee;
}

/* gradation lines */
.c3 .c3-axis line {
stroke: #eee;
}

/* gradation text */
.c3 .c3-axis text {
fill: #eee;
}

… will do it. Obviously, you want to replace #ccc with the color.

However, by looking at the picture you posted, it looks like you played around with the fill property of .c3 .domain. You want that reset back to white or transparent.

var chart = c3.generate({
bindto: ‘#chart’,
data: {
columns: [
[‘data1’, 30, 200, 100, 400, 150, 250],
[‘data2’, 50, 20, 10, 40, 15, 25]
]
}
});
/* axis line */
.c3 .domain {
stroke: #eee;
}

/* gradation lines */
.c3 .c3-axis line {
stroke: #eee;
}

/* gradation text */
.c3 .c3-axis text {
fill: #eee;
}
<script src=”https://cdnjs.cloudflare.com/ajax/libs/d3/5.9.2/d3.min.js"></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.1/c3.min.js"></script>
<link href=”https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.1/c3.min.css" rel=”stylesheet”/>

<div id=”chart”></div>

[Vue.js] Vue component state freezing when moved between router-views Subscribe to RSS

there is a custom map component, which wraps a Openlayers 4 instance. This component which when forced to use, is used multiple places across my SPA. The initialization process is quite long, so I would like to keep one instance of the map available, and move it between views when I need to. Problem is that the state doesent update within the component when it has moved.

Ive boiled the problem down to this fiddle: https://jsfiddle.net/j16d4yto/
When moved on the same router-view the state updates fine (click the Change text button). But when the router-view changes, and the component is moved with appendChild to the new div, the state freezes, and you cant update the text variable anymore.

This is how I move the component from one element to another:

this.$root.$on(‘showMoveableComponent’, function(element) {
element.appendChild(thisElement);
this.text = ‘Changed text2’;
});

I bet when doing something wrong here, and probably also approaching this problem in the wrong way?

Thanks!

Solution :

It’s not working because of when router-view changed the MoveableComponent has been destroyed only its DOM element still referenced by you. You can test by print something in destroyed lifecycle callback function.

So this mean you can solve this by using built-in keep-alive component:

<keep-alive>
<router-view></router-view>
</keep-alive>

Example

The keep-alive component will cache everything which may not good in some other cases.

In my opinion the better way to solve this is create another vue.js instance and move it.

const MoveableComponent = new Vue({
el: ‘#some-id’,
template: `…`,
data: { … },
methods: {
changeText() {

},
moveTo(element) {
element.appendChild(this.$el)
}
}
})

Example

[Vue.js] I would like to understand vue.js components and databinding with userinteractions, Can anyone correct my code and explain it to me? Subscribe to RSS

I’m a beginner developer , currently I’m working on a weather app project with vue.js . there is some problems with components and databinding with vue. Can anyone explain it to me with some code sample?!

I’ve read some forums, and watched some tutorial videos about custom components , tried it as well but i think I made some mistakes.
Specificly i would like to know, how can i bind my API url data to a dropdown box, that the location changes with every selection.

note: Used API is an open weather API, based on latitude and longitude locations.

var myDropdown = Vue.component(‘my-dropdown’, {
template: ‘#dropdown’,
data: function() {
return {
isOpen: false,
selected: null,
options: [
‘Heidenheim an der Brenz’,
‘Giengen’,
‘Ulm’,
]
}
},
methods: {
toggle: function() {
this.isOpen = !this.isOpen;
},
show: function() {
this.isOpen = true;
},
hide: function() {
this.isOpen = false;
},
set: function(option) {
this.selected = option;
this.hide();
}
},
mounted: function() {
console.log(‘My dropdown component is mounted!’)
}
});

let weatherApp = new Vue({
el: ‘#app’,
data: {
town: ‘’,
Temp: ‘’,
minTemp: ‘’,
maxTemp:’’,
wind: ‘’,
description: ‘’,
icon: ‘’,
hdh: ‘https://fcc-weather-api.glitch.me/api/current?lat=48.6833&lon=10.15',
ulm: ‘https://fcc-weather-api.glitch.me/api/current?lat=48.39841&lon=9.99155',
giengen: ‘https://fcc-weather-api.glitch.me/api/current?lat=48.39841&lon=9.99155'
},
methods: {
getWeather() {
var url = ‘’;
axios
.get(url)
.then(response => {
this.town = response.data.name
this.Temp = response.data.main.temp;
this.minTemp = response.data.main.temp_min;
this.maxTemp = response.data.main.temp_max;
this.wind = response.data.wind.speed;
this.description = response.data.weather[0].description;
this.icon = response.data.weather[0].icon;
})
.catch(error => {
console.log(error);
});
},
},
beforeMount() {
this.getWeather();
},
});
body {
background: url(https://shiftyjelly.files.wordpress.com/2013/11/w.jpg?w=960&h=400);
background-repeat: no-repeat;
font-family: ‘Montserrat’, sans-serif;
font-weight: 100;
text-shadow: 0px 0px 2px #000000;
color: #ffffff;
width: 960px;
height: 400px;
}

#weather {
padding: 15px;
}

#temperature {
position: absolute;
font-size: 40px;
top: 240px;
left: 420px;
color: black;
}

#temp-values {
text-align: right;
position: relative;
text-justify: distribute;
display: block;
top: 60px;
left: -200px;
color: black;
}

#info {
padding: 15px;
}

#name {
top: 10px;
left: 300px;
font-size: 40px;
color: black;
position: relative;
}

.wind {
top: 180px;
left: 380px;
color: black;
position: relative;
}

#icon {
color: black;
font-size: 20px;
left: -180px;
top: 120px;
position: relative;
}

#my-dropdown {
cursor: pointer;
position: absolute;
left: 0%;
top: 0%;
min-width: 250px;
height: 40px;
}

#selected {
position: relative;
z-index: 2;
display: block;
width: 100%;
height: 40px;
padding: 0 20px;
background: rgba(05, 46, 41, 0.1);
border-radius: 10px;
font: 1.25rem/40px ‘Ubuntu’, Helvetica, Arial, sans-serif;
text-shadow: 2px 2px 0px #000;
color: rgb(0, 237, 255);
}

#selected: after {
opacity: 0.5;
display: inline-block;
margin-left: 10px;
content: ‘’;
color: black;
}

#selected:hover: after {
opacity: 1;
}

#options {
position: absolute;
left: 0;
top: 100%;
z-index: 1;
width: 100%;
margin-top: 3px;
background: rgba(05, 46, 41, 0.1);
border-radius: 10px;
}

#option {
padding: 5px 20px;
border-bottom: 1px solid rgba(0, 0, 0, 0.25);
font: 1.2rem ‘Vollkorn’, Georgia, Times, serif;
color: rgb(0, 237, 255);
text-shadow: 2px 2px 0px #000;
}

#option:hover {
background-color: rgba(0, 0, 0, 0.05);
}

#option:last-child {
border-bottom: none;
}

#fade-enter-active, .fade-leave-active {
transition: all 0.25s ease-out;
}

#fade-enter, .fade-leave-active {
opacity: 0.5;
transform: translateY(-30px);
}

* { box-sizing: border-box; }
<html>
<head>
<meta charset=”utf-8”>
<meta http-equiv=”x-ua-compatible” content=”ie=edge”>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.js"></script>
<title>Weather App</title>
<meta name=”viewport” content=”width=device-width, initial-scale=1”>
</head>
<template id=”dropdown”>
<div id=”my-dropdown”>
<div id=”selected” @click=”toggle”>Select the Town Here</div>
<div id=”options” v-show=”isOpen”>
<div id=”option” v-for=”option in options” @click=”set(option)”>
{ option }
</div>
</div>
</div>
</template>
<body>
<div id=”app”>
<my-dropdown></my-dropdown>
<div id=”weather”>
<span id=”name”>{town}</span>
<span id=”icon”>{description}</span>
<span id=”temperature”>{Temp}</span><br>
<span id=”temp-values”>Min: {minTemp} <br> Max: {maxTemp}</span>
</div>
<div id=”info”>
<img class=”wind” height=”40px” width=”40px” src=”https://www.svgrepo.com/show/71601/wind.svg">
<span class=”wind”>{wind} m/s</span>
</div>
</div>
<script src=”https://unpkg.com/axios/dist/axios.min.js"></script>
<script src=”https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</body>

</html>

Solution :

Here is a fiddle

First, it’s best to keep all of the data in one place rather than hard-coding the town names in the dropdown component. You also don’t need to store the whole url each time. So remove options from the dropdown. You’ll pass the town data to it via prop.

1) Restructure the app’s town data into an array of objects like this:

data: {

towns: [
{abbr: ‘hdh’, name: ‘Heidenheim an der Brenz’, lat: ‘48.6833’, lon: ‘10.15’},
{abbr: ‘ulm’, name: ‘Ulm’, lat: ‘48.39841’, lon: ‘9.99155’},
{abbr: ‘giengen’, name: ‘Giengen’, lat: ‘48.39841’, lon: ‘9.99155’}
]
}

2) Pass the town data via prop named “options” to the dropdown component:

<my-dropdown :options=”towns”></my-dropdown>

3) Change the dropdown label to { option.name }

4) Add the prop to the component:

props: [‘options’]

5) Emit a custom event when the town changes:

set: function(option) {
this.$emit(‘change-town’, option);

}

6) Process that event in the parent template’s getWeather:

<my-dropdown :options=”towns” @change-town=”getWeather”></my-dropdown>

7) Generate the URL and send the request:

getWeather(option) {
const urlpath = ‘https://fcc-weather-api.glitch.me/api/current?'
const qs = `lat=${option.lat}&lon=${option.lon}`;
const url = path + qs;
axios.get(url)…

}

[Vue.js] Email notification whenever a comment is created via WP REST API Subscribe to RSS

I’m building a custom comment form for my Vue.js & WordPress Single Page Application theme and was able to post a comment via ajax POST request to the WP REST API. But I don’t get any admin notifications on a new comment even the settings in Settings–>Reading are set to notify the admin each time a comment is created/added.

So how can I get email notifications on WP REST API comment creation?

Solution :

For any reason the WP REST API team didn’t use the function wp_new_comment whenever a comment is added/created. This function includes the comment_post action hook which, in turn, is used by WordPress to send admin notifications in wp-includes/default-filters.php.

Instead they’ve used the wp_insert_comment() function which is defined in wp-includes/comments.php and which also includes an action hook of the same name wp_insert_comment at the very end of the function. This hook we can use to trigger the notification function wp_new_comment_notify_moderator(). Just add the following snippet into the theme’s / plugin’s functions.php

add_action( ‘wp_insert_comment’, ‘wp_new_comment_notify_moderator’ );

see also:

https://core.trac.wordpress.org/ticket/40352

https://wordpress.org/support/topic/wp-api-comments-not-sending-notifications/#post-8987973

[Vue.js] Install Vue 2 in a Phoenix 1.4 Application with Webpack 4 Subscribe to RSS

to install vue.js 2 in a new Phoenix 1.4 project.

when using Webpack 4. The documentation for vue.js does not provide much guidance.

Solution :

Install Vue:

cd assets/

npm install vue.js vue-loader vue-template-compiler –save

In webpack.config.js add the following lines where appropriate, heeding existing configuration:

const { VueLoaderPlugin } = require(‘vue-loader’);

module.exports = (env, options) => ({
module: {
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
loader: ‘vue-loader’,
},
],
},
plugins: [
new VueLoaderPlugin(),
],
resolve: {
alias: {
‘vue$’: ‘vue/dist/vue.esm.js’,
},
},

This Webpack config will need to be merged with what is already shipped with the Phoenix project.

Create a folder for the vue.js components (i.e., the .vue.js files):

mkdir js/components/

In assets/js/app.js add:

import vue.js from ‘vue’;
const files = require.context(‘./components/‘, true, /\.vue$/i);
files.keys().map(key => Vue.component(key.split(‘/‘).pop().split(‘.’)[0], files(key).default));
document.addEventListener(‘DOMContentLoaded’, function(event) {
const app = new Vue({
el: ‘#app’,
});
});

Be sure to add an #app ID to an element somewhere in the layout.

[Vue.js] How to add custom-logo/image in toolbar using vuetify Subscribe to RSS

when trying to add image/custom logo in the toolbar using Vuetify.
when using v-toolbar to create the navigation bar.

The image is not showing up. It shows the error of [Vuetify] Image load failed
src: ../assets/mad_logo.png

I tried using <v-img>
But it did not work.

This is how the navigation bar looks like

This is the code:

VuetifyTest.js

<v-toolbar
color=”primary”
\>

<v-toolbar-side-icon>
<v-img src=”../assets/mad_logo.png” />
</v-toolbar-side-icon>
<v-toolbar-title class=”black–text”>Title</v-toolbar-title>

<v-spacer></v-spacer>
<v-avatar>
<img
src=”../assets/static.jpeg”
alt=”John”
\>
</v-avatar>

</v-toolbar>

</template>

<script lang=”js”>
export default {
name: ‘profile’,
props: [],
mounted() {

},
data() {
return {

}
},
methods: {

},
computed: {

}
}
</script>

<style scoped >

</style>

This is the directory structure:

How do I attach the logo on the top left of the navigation bar and load the image correctly.

Any code changes would work.
Thanks!

Solution :

Try to use :

<v-img :src=”require(‘@/assets/mad_logo.png’)” >

Solution 2:

there is try to put this HTML <img src=”/assets/mad_logo.png” height=”20px”> and it is appear to be ok on my toolbar.