link2740 link2741 link2742 link2743 link2744 link2745 link2746 link2747 link2748 link2749 link2750 link2751 link2752 link2753 link2754 link2755 link2756 link2757 link2758 link2759 link2760 link2761 link2762 link2763 link2764 link2765 link2766 link2767 link2768 link2769 link2770 link2771 link2772 link2773 link2774 link2775 link2776 link2777 link2778 link2779 link2780 link2781 link2782 link2783 link2784 link2785 link2786 link2787 link2788 link2789 link2790 link2791 link2792 link2793 link2794 link2795 link2796 link2797 link2798 link2799 link2800 link2801 link2802 link2803 link2804 link2805 link2806 link2807 link2808 link2809 link2810 link2811 link2812 link2813 link2814 link2815 link2816 link2817 link2818 link2819 link2820 link2821 link2822 link2823 link2824 link2825 link2826 link2827 link2828 link2829 link2830 link2831 link2832 link2833 link2834 link2835 link2836 link2837 link2838 link2839 link2840 link2841 link2842 link2843 link2844 link2845 link2846 link2847 link2848 link2849 link2850 link2851 link2852 link2853 link2854 link2855 link2856 link2857 link2858 link2859 link2860 link2861 link2862 link2863 link2864 link2865 link2866 link2867 link2868 link2869 link2870 link2871 link2872 link2873 link2874 link2875 link2876

[Vue.js] Cannot read property 'upgrade' of undefined when starting vue application

there is a project that’s been running perfectly for a few months now, able to run npm run serve with no problem. there is to terminate and run the command again whenever I switch networks, but that has never been a problem and the server could always start again.

Until now - no matter what I do I can’t get the server to start. I get this error:

npm run serve

\> xbs@0.6.2 serve D:\workspace\[PROJECT]
\> vue-cli-service serve

INFO Starting development server…
10% building 1/1 modules 0 active ERROR TypeError: Cannot read property ‘upgrade’ of undefined
TypeError: Cannot read property ‘upgrade’ of undefined
at Server.<anonymous> (D:\workspace\[PROJECT]\node_modules\webpack-dev-server\lib\Server.js:667:47)
at Array.forEach (<anonymous>)
at new Server (D:\workspace\[PROJECT]\node_modules\webpack-dev-server\lib\Server.js:666:22)
at serve (D:\workspace\[PROJECT]\node_modules\@vue\cli-service\lib\commands\serve.js:137:20)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

The last time I got this message was when I forgot to set the .env files, but this is a previously working copy with all necessary files set, and no changes since the last working run.

I’ve even tried pulling a fresh copy of the repo, running npm i and setting all env files but it still fails.

npm run lint and npm run build can still work, only npm run serve.

Am I missing anything?

Solution :

The problem was again with the .env files. My vue.config.js was trying to access a previously set environment variable that had since been removed.

Only strange thing was that there weren’t any problems up til now?

[Vue.js] Making an Ajax call for Vue multiselect options in Laravel

I’m trying to convert autocomplete functionality from Jquery with an input into a vue.js multiselect.

I’m most of the way there but I still have some errors or incompletions somewhere here. there is a basic div with the multislect which shows on the page. Then there is the vue.js instance which is where I’m making a call to my Route (the route is hit successfully and it triggers the function in my controller below)

My biggest issue, I believe, is there is no idea how to make the multiselect search act as my query in the ajax call so that I can populate my options in the vue.js instance.

What am I missing/doing wrong here?

HTML:

<div id=”app”>
<multiselect v-model=”value” open-direction=”bottom” :options=”options” :multiple=”true” :close-on-select=”false” :taggable=”true” :clear-on-select=”false” :preserve-search=”true” placeholder=”Choose Option(s)” label=”name” track-by=”name”>
<template slot=”selection” slot-scope=”{ values, search, isOpen }”><span class=”multiselect__single” v-if=”values.length && !isOpen”>{ values.length } options selected</span></template>
</multiselect>
</div>

Vue:

let app = new Vue({
components: {
Multiselect: window.VueMultiselect.default
},
data () {
return {
selected: ‘A’,
options: []
}
},
methods:{
pullEmployees(){

$.ajax({
url:”{ route(‘campaigns.search’) }”,
method:”POST”,
data:{query:query, _token: ‘{ csrf_token() }’},
success: results => this.options = results
});
}
}
}).$mount(‘#app’);

Controller:

public function searchTags(Request $request)
{

if($request->get(‘query’))
{
$query = $request->get(‘query’);
$data = CampaignTags::where(‘TAG_DATA’, ‘LIKE’, “%{$query}%”)->get();

return $data;
}
}

Solution :

One thing that comes to my attention is that you are using success: results => this.options = results in the success function for the ajax request. One common mistake is that this in this particular context doesn’t refer to the vue.js instance but the ajax request.

So what could get you a step further is to create an explicit reference to the vue.js instance upfront:

pullEmployees() {
var vue.js = this;
$.ajax({
url:”{ route(‘campaigns.search’) }”,
method:”POST”,
data:{query:query, _token: ‘{ csrf_token() }’},
success: results => vue.options = results
});
}

This should at least set the the vue.js instance options to the results provided by the ajax request.

Maybe you can proceed further with this information.

[Vue.js] Why is this Vue prop not reacting to change?

there is a Prop in my component that is a User object, I then have this function:

onChange: function(event){
this.$v.$touch();
if (!this.$v.$invalid) {
this.$axios.put(‘update’,{
code:this.user.code,
col:event.target.name,
val:event.target.value
}).then(response => {
this.user[event.target.name]=event.target.value
});
}
}

I can see in the vue.js console debugger that the correct attribute has been updated, this attribute exists when the component is created but the template where I reference it does not refresh:

<p>Hi {user.nickname}, you can edit the details here:</p>

This is all within the same component so I’m not navigating to child or parent. I’m sure props have been reactive elsewhere in my code?

Solution :

Ok, it seems this is intended behaviour. According to the documentation
https://vuejs.org/v2/guide/components-props.html in the scenario that there is it should be handled as:

The prop is used to pass in an initial value; the child component wants to use it as a local data property afterwards. In this case,
its best to define a local data property that uses the prop as its
initial value:

props: [‘initialCounter’],
data: function () {
return {
counter: this.initialCounter
}
}

Solution 2:

Usually components should be reactive to Props, though there is had experiences where it was non-reactive so i added the prop to a watcher and put the functional call there.

props: [“myProp”],
watch:{
myProp(){
// … the functions here
}
}

[Vue.js] nuxt-link as an image

What do there is to do to use a nuxt-link as an image?

When I display an image in Vue, I usually do:

<img src=”~assets/icons/filterLinkButton.svg”>

but when I do the same with a nuxt-link, the path to the file does not get evaluated.

# this is not working

<nuxt-link
tag=”img”
src=”~assets/icons/filterLinkButton.svg”
to=”/locations”>
</nuxt-link>

What can I do to solve this?

EDIT:

It works though if I do:

<template>
<nuxt-link
:src=”image”
tag=”img”
to=”/locations”>
</nuxt-link>
</template>

<script>
import image from ‘~/assets/icons/filterLinkButton.svg’

export default {
data() {
return {
image: image
}
}
}
</script>

Solution :

Well according to the documentation if you’re using webpack you can use that alias (~assets) inside the css files, but apparently you need to use the ~/ version on the template, also take a look at the approach bellow using the static folder I think that suits you better since the asset you used in the question can be placed in the static folder and get rid of the alias

[Vue.js] Automatic refresh with specific request - VueJS, Axios

During the development of a single page application in VueJS, I’ve noticed a strange behavior with two different requests with Axios.

This first request returns a normal result and can be processed as it to be.
HTTP is only the object created by axios.create

const initGit = {
das: this.message,
password: this.password
};
HTTP.post(‘git/initGit’, qs.stringify(initGit), this.config)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});

This request works like a charm :-)

However, when I replace this first request with the request below.

const body = {
skill : this.newSkill
};
HTTP.post(‘git/pushGit’, qs.stringify(body), this.config)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});

It causes a page refresh.

I had this behavior in the method part of my vue.js file. I’ve tried in the watch part as well but the behavior is the same.

I definitely don’t understand how one of two requests which work when I check on the network tab in console causes a refresh even before the response of the server.

Please help !!!! :-)

Solution :

@varit05 This is the template code of my stepper step which includes the call to the watcher to realize the 2 requests.

<v-stepper-content step=”3”>
<v-form onsubmit=”return false;”>
<div class=”new-skill-step”>
<v-text-field
v-model=”newSkill”
:rules=”[rulesDas.required]“
outline
clearable
label=”New Skill”
type=”text”
@keyup=”isButtonNewSkillEnabled”
@keyup.enter=”sendNewSkill = ‘’”
\>
</v-text-field>
<v-btn :disabled=”!buttonWriteSkillEnabled” round color=”primary” @click=”sendNewSkill = ‘’”>
Write new skill
</v-btn>
</div>
</v-form>
</v-stepper-content>

Solution 2:

I’ve tried to move the HTTP request part of my program in another method. It still refeshes the page.

What is wrong with that request ?

NEED HELP PLZ :-)

[Vue.js] 'i is not defined' at FileReader.reader.onload VueJs

I cant execute a for loop nor a forEach in an array because its says that i is not defined

there is already tried to use a while, a for, a for each. Use i like a vue.js data variable.
I set that let self = this, because the scope changes within that reader.onload. and I know that the problem has to be with something like that.

<template>
<div>
<p>My File Selector: <file-select v-model=”file”></file-select></p>
<p v-if=”file”>{file.name}</p>
<v-btn v-if=”file” @click=”importFile”>Import</v-btn>
<div id=”fileContents”>

</div>
</div>
</template>

<script>
import icsToJson from ‘ics-to-json’
import FileSelect from ‘./FileSelect.vue’

export default {
name: “ViewImport”,
components: {
FileSelect
},
data(){
return {
file: null,
fileInJson: null,
categories: [],
importExists: false,
i
}
},
created(){
this.getCategories();
},
methods:{
getCategories(){
//this works
},
importCreatingCategoryImport(){
//code, this works
},
doesImportExists(){
for (var i = 0; i < this.categories.length; i++){
if (this.categories[i].category.name === ‘Import’){
this.importExists = true;
// break;
}
}
},
importFile(){
if (this.file) {
let reader = new FileReader();
reader.readAsText(this.file, “UTF-8”);
let self = this;
reader.onload = function (evt) { //If everything works
//Changes the file to format JSON
self.fileInJson = icsToJson(evt.target.result);

self.doesImportExists();//the loop

if (self.importExists){
console.log(‘Category exists’);
//other method
}else{
console.log(‘not working’); //Because its in my BD
// self.importCreatingCategoryImport();
}

};
reader.onerror = function (evt) { //if it doesn’t
document.getElementById(“fileContents”).innerHTML = “error reading file”;
}
}
},

}
}
</script>
//style commented

Solution :

That’s because in the data section you have not assigned a value to key i. You should do i : 0 in the data, and in for loop let j = this.i; j < this.categories.length; j++)

[Vue.js] Toggle list to display based on selected radio button

there is a piece of code that asks the user where they want to display their ad. The options are and there is them as radio buttons:

All states
select states
all states except the following…

the lists of states to appear to the user when they either select ‘select states’ or ‘all states except the following’.

This is what i tried but wasn’t able to get it working:

showStates: boolean = false;

.form-check
input.form-check-input(type=”radio”)
label All States

.form-check
input.form-check-input(type=”radio” @click=’showStates = !showStates’)
label all states except except:

.form-check
input.form-check-input(type=”radio” @click=’showStatus = !showStates’)
label selected states:

view page

(div to show states)
.collapse.container(v-show=’showStates’)

Select states.
.col-6(v-for=’location in locationList’)
.form-check
input.form-check-input(type=’checkbox’)
label.form-check-label {location.name}

how can i get this so the states div only show when i click on the two radio buttons?

Solution :

Radio buttons only emit change events. Try using @change instead of @click.

[Vue.js] Vue.js + SVG Map - how to style selected item?

there is SVG map and .selected class in my which adds color to the selected province:

.selected {
fill: brown;
}

I cannot add any methods or events to HTML directly, because I will use different maps.

I use an event listener in my methods to access data and render it based on the province that was clicked.

How can I do it with the .selected class? So if I click the given province it get a .selected class and if I click another one the previous one loses the .selected class?

Here is my snippet with my code: https://mdbootstrap.com/snippets/jquery/marektchas/507954

Solution :

You can add the .selected class programmatically.

First add a new method to remove the class on all paths, then add the class for the selected element on click:

methods: {

removeSelection (paths) {
paths.forEach(el => el.classList.remove(“selected”))
},

addClickHandler() {
let paths = this.$el.querySelectorAll(‘path’)
paths.forEach(el => {
let id = el.attributes.id.value
el.addEventListener(‘click’, () => {
this.province = this.provinces.find(province => province.id == id)

this.removeSelection(paths)
el.classList.add(“selected”)

// Animation
this.isActive = true
setTimeout(() => { this.isActive = false }, 200)
})
})
}
}

Solution 2:

You can use a conditional class binding as described in the vue.js docs under Class & Style Bindings

In the case, this could look like

<path d=”…snip…”
id=”AL” name=”Albania” :class=”{selected: province.id == ‘AL’}”>
</path>

Since this would force you to add the comparison for each province, I’d suggest you render the SVG dynamically:

Add the SVG path to the province’s data, e.g. { id: ‘LT’, name: ‘Lithuania’, vat: 21, path=’M707.9 … 0.5z’ }
Since you can simply create SVG using vue.js you can render the provinces in a loop and bind all it’s properties, e.g.

<path v-for=”p in provinces” :key=”p.id”
:d=”p.path”
:id=”p.id”
:name=”p.name”
:class=”{selected: province.id == p.id}”>

Going this way would significantly shrink the markup.

[Vue.js] How to import and use image in a Vue single file component?

I think this should be simple, but when facing some trouble on how to import and use an image in vue.js single file component. Can someone help me how to do this? Here is my code snippet:

<template lang=”html”>
<img src=”zapierLogo” />
</template>

<script>
import zapierLogo from ‘images/zapier_logo.svg’

export default {
}
</script>

<style lang=”css”>
</style>

there is tried using :src, src=”{ zapierLogo }”, etc but nothings seems to work. was not able to find any example too. Any help?

Solution :

As simple as :

<template>
<div id=”app”>
<img src=”./assets/logo.png”>
</div>
</template>

<script>
export default {
}
</script>

<style lang=”scss”>
</style>

Taken from the project generated by vue.js cli.

If you want to use the image as a module, do not forget to bind data to the vuejs component

<template>
<div id=”app”>
<img :src=”image” />
</div>
</template>

<script>
import image from “./assets/logo.png”

export default {
data: function () {
return {
image: image
}
}
}
</script>

<style lang=”scss”>
</style>

And a shorter version :

<template>
<div id=”app”>
<img :src=”require(‘./assets/logo.png’)” />
</div>
</template>

<script>
export default {
}
</script>

<style lang=”scss”>
</style>

Solution 2:

If you wish to load them by webpack you can simply use :src=’require(‘path/to/file’)’ Make sure you use : otherwise it won’t execute the require statement as Javascript.

Solution 3:

I came across this issue recently, and i’m using Typescript.
If you’re using Typescript like I am, then you need to import assets like so:

<img src=”@/assets/images/logo.png” alt=””>

[Vue.js] How to auto change page with vue-router?

As the title suggests, there are two pages in the code. to show the page HelloWorld first then show next page myPage without any click.
(maybe 2 sec after..) How to auto change a page with vue-router?

I know should set some code in setTimeout function.

index.js

import vue.js from ‘vue’
import Router from ‘vue-router’
import HelloWorld from ‘@/components/HelloWorld’
import myPage from ‘@/components/myPage’

Vue.use(Router)

export default new Router({
routes: [{
path: ‘/‘,
name: ‘HelloWorld’,
component: HelloWorld
},
{
path: ‘/myPage’,
name: ‘myPage’,
component: myPage
}
],

})

Solution :

If you wish to transition from HelloWorld to MyPage component then use created or mounted hook of the HelloWorld component like this:

created() {
setTimeout(() => {
// You can also use replace() instead of push()
this.$router.push(‘/myPage’);
}, 2000);
}

Read more about hooks here.

Solution 2:

You will have to do that in the HelloWorld.vue.js file. You will have something like this in the mount function of the HelloWorld.vue.js file

mounted() {
setTimeout(() => {
this.$router.push(‘/next-route’)
}, 2000)
}

Hope that helps