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] What is the difference between this two very basic vue app?

I’ve been learning Vue.js and I tried to have the root instance not erase the html content I put inside. The idea being that I could have a normal html page and vue.js “watching” the main wrapper and if it run into a vue.js component it will be render by vue. I’ve managed to do that when I import the CDN of vue.js but not with the vue.js cli somehow. I don’t understand the difference.

I made this codepen loading vue.js by the cdn and it render without problem

<div id=”app”>
<h1>My Vue.js App</h1>
<p>{ message }</p>
</div>

new Vue({
el: ‘#app’,
data: {
message: ‘Hello world’
}
});

https://codepen.io/cvallee/pen/dLKVEP

But in codesandbox where it use vue.js cli nothing is render, the content of the root element flash and then disappear from the dom. No matter what I put into the main div it is erase as soon as the app mount. https://codesandbox.io/s/m5qvm40nkx

Solution :

I think the issue has to do with the way that the CodeSandbox loads the vue.js app and triggers the initial render. If you add an App.vue.js file and change the main.js file to

import vue.js from “vue”;
import App from “./App.vue”;

// Vue.config.productionTip = false;

new Vue({
el: “#app”,
render: h => h(App)
});

and the index.html to

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8” />
<meta http-equiv=”X-UA-Compatible” content=”IE=edge” />
<meta name=”viewport” content=”width=device-width,initial-scale=1.0” />
<link rel=”icon” href=”<%= BASE_URL %>favicon.ico” />
<title>codesandbox</title>
</head>
<body>
<div id=”app”></div>
</body>
</html>

it works for me this way. Here is the working version - https://codesandbox.io/s/84ox08k24j

[Vue.js] How do I use a heatmap with vue highcharts?

I tried using heatmap as the chart type but when getting error 17. when using vue-highcharts and wondering how I can fix this proble. I looked online and it seems that I may have to import it and use it. Can anyone show me how to do that because I can’t find any documentation on it?

Solution :

import HighCharts from ‘highcharts’
import heatmap from ‘highcharts/modules/heatmap’;

heatmap(HighCharts);

These are the import statements for it to work.

[Vue.js] Is it possible to integrate multiple front end apps, one in vue and another in react, with a single laravel backend?

there is inherited a laravel code base that has a vue.js app integrated with it(inside resources/assets/js) through laravel-mix. when asked to develop some front-end feature with react. to know if I can configure webpack.mix.js and the laravel routes so that the react app can be integrated into the laravel app without affecting the vue.js application.

Solution :

So here is how I resolved my own question, and successfully integrated two separate react apps, and one vue.js app against a laravel backend.

Updated my webpack.mix.js file as follows:

mix
.react(“resources/assets/js-calendar/app.js”, “public/js-calendar”)
.sass(“resources/assets/sass-calendar/app.scss”, “public/css-calendar”)
.react(“resources/assets/js/app.js”, “public/js”)
.sass(“resources/assets/sass/app.scss”, “public/css”)
.js(“resources/assets/js-vue/app.js”, “public/js-vue”)
.sass(“resources/assets/sass-vue/app.scss”, “public/css-vue”);

The content of my resources/assets folder was:

js
components
js-calendar
components
js-vue
components
sass
sass-calendar
sass-vue

Had the following three blade templates in my resources/views folder:

app.blade.php hello.blade.php welcome.blade.php

And the content of web.php file was:

Route::view(‘/calendar/{path?}’, ‘app’);
Route::view(‘vue/{path?}’, ‘hello’);
Route::view(‘/{path?}’, ‘welcome’);

And finally the compiled css and js files were linked in the blade files like this:


<link href=”{ asset(‘css-calendar/app.css’) }” rel=”stylesheet”>
</head>
<body>
<div id=”app”></div>

<script src=”{ asset(‘js-calendar/app.js’) }”></script>
….

The above was for the app.blade.php. For the hello.blade.php the css and js src links respectively were css-vue/app.js and js-vue/app.js. And for the welcome.blade.php, the src links were css/app.css and js/app.js.

Notice how yarn run dev generates the respective css and js files in separate destinations:

/js-calendar/app.js 9.45 MB 0 [emitted] [big] /js-calendar/app
/js/app.js 2.14 MB 1 [emitted] [big] /js/app
/js-vue/app.js 1.43 MB 2 [emitted] [big] /js-vue/app
/css-calendar/app.css 219 kB 2 [emitted] /js-vue/app
/css/app.css 219 kB 2 [emitted] /js-vue/app
/css-vue/app.css 219 kB 2 [emitted] /js-vue/app

I had both vue.js and react dependencies and their entries added to the package.json.

[Vue.js] How to pass paramter from Vue root to component?

when trying to pass a string from vue.js root to component, when rather new to vue.js and not sure how to correctly pass data.

the parameter when trying to pass is: userId

View: Index.cshtml ( this is where i get my parameter )

@using Microsoft.AspNetCore.Identity
@inject SignInManager<User> SignInManager
@using LaBouteilleDamour.Domain.Models;
@inject UserManager<User> UserManager

@if (SignInManager.IsSignedIn(User))
{
User user = await UserManager.GetUserAsync(User);
var userid = UserManager.GetUserId(User);

<div id=”cartApp” userId:”userid”></div>
<script src=”./js/Cart.bundle.js” asp-append-version=”true”></script>
}

vue.js root: Cart.boot.ts

import vue.js from “vue”;
import Cart from “./Components/Cart.vue”;

new Vue({
el: “#cartApp”,
template: ‘<Cart :userId=”userId” />’,
props: {
*userId: String,
},
components: {
Cart
}
});

vue.js Component: Cart.vue.js ( where i need the parameter to go )

<template>
/*HTML*/
</template>

<script lang=”ts”>
import ShoppingCartItem from “../Components/ShoppingCartItem.vue”;
import ShoppingCartService, { ICartItem } from “./AP
/ShoppingCartService”;
import vue.js from “vue”;

interface IShoppingCartpageData {
items: ICartItem[],

}

export default Vue.extend({
data(): IShoppingCartpageData {
return {
items: [],
}
},
props: {
userId: {
type: String,
required:true,
}
},

})
</script>

Solution :

You are passing “userId” in the template but userId is not defined in the vue’s data function and hence is not reactive which means you cannot use it in DOM unless you declare it in data function.

Also root view does not require props, props should have only those element which the component is going to receive from the parent component.

So the code for root element must look something like this

import vue.js from “vue”;
import Cart from “./Components/Cart.vue”;

new Vue({
el: “#cartApp”,
template: ‘<Cart :userId=”userId” />’,
data: function(){
return {
userId: userid, // Accessing userId from global scope as it is defined in Index.cshtml.
}
},
components: {
Cart
}
});

[Vue.js] How can I use proxyTable to make cross origin request in vue-cli?

to use proxyTable with axios in my vue-cli project.

In my config/index.js, I put code like this:

proxyTable: {
‘/getnews’: {
target: ‘https://xx.xxx.xx.x'
changeOrigin: true,
secure: false,
pathRewrite: {
‘^/getnews’: ‘/getnews’
}
}
}

and in my request function, it goes like this:

var url = ‘/getnews’;
this.$axios({
methods: ‘get’,
url: url,
})
.then(response => {
console.log(response);
})

Now here comes the question, my browser console tells me that

xhr.js?ec6c:178 GET http://localhost:8080/getnews 504 (Gateway Timeout)

and the terminal says:

Error occurred while trying to proxy request /getnews from localhost:8080 to https://xx.xxx.xx.x (ECONNREFUSED)

so it looks like the proxy doesn’t work out, my request still goes to my localhost. Anyone knows how to fix that?

Solution :

I finally figure out with the help of my friend.
It’s the lack of port number that causing the problem. The code should be like this:

proxyTable: {
‘/getnews’: {
target: ‘https://xx.xxx.xx.x:8080'
changeOrigin: true,
secure: false,
pathRewrite: {
‘^/getnews’: ‘/getnews’
}
}
}

Then it works just fine.

[Vue.js] What exactly does computed properties in vuejs?

There are couple of questions related computed properties like the following

“vuejs form computed property”
“Computed properties in VueJs”
“computed property in VueJS”
“Use computed property in data in Vuejs”

They are asking about specific error or logic. There are lot of websites that are explaining about vuejs related concepts. I read about computed properties on vuejs official website. When we do complex calculations or want to avoid to write more logic in our html template then we use computed properties.

But could not get any solid understanding about computed properties, when it calls, how it calls, what exactly do?

Solution :

TL;DR: Computed properties are getters/setters in Vue.

When defined in the shorthand form, they are getters:

computed: {
someComputed() {
return `${this.foo} ${this.bar}`;
}
}

is equivalent with

computed: {
someComputed: {
get: function() {
return `${this.foo} ${this.bar}`;
}
}
}

which can also have a setter:

computed: {
someComputed: {
get: function() {
return `${this.foo} ${this.bar}`;
}
set: function(fooBar) {
const fooBarArr = fooBar.split(‘ ‘);
this.foo = fooBarArr[0];
this.bar = fooBarArr[1];
}
}
}

In short, vue.js computed properties allow you to bind an instance property to

a getter: function run when you look up that property; usage:

this.someComputed // returns the computed current value, running the getter.

a setter: function run when you attempt to assign that property; usage:

this.someComputed = value; // sets the computed current value, running the setter.

Read more on getters and setters in Javascript.

And here’s the documentation on vue.js computed properties.

Solution 2:

You can use computed properties when for example you have some logic what will blow up the template.

The idea is, that normally you want to keep all javascript logic in the javascript side of the vue.js component, and only access final data in the data (if possible)

For that you can use computed props, which normally are doing simple things like:

computed: {
// a computed getter
reversedMessage: function () {
// `this` points to the vm instance
return this.message.split(‘’).reverse().join(‘’)
}
}

Or an another good example if you have some currency and you want to format it with thousand separator and euro ign at the end.

Then you can access the computed prop in the template like you access a normal prop, you dont have to call it as a function.

like so:

<div>{reversedMesage}</div>

Every time, when any variable what is used in the conputed prop is changing, vue.js vill take care of it and will re-calculate the computed property again.

Lets say you have the following:

computed: {
prettyAmount: function () {
return this.amount + ‘ ‘ + this.currency.toUpperCase()
}
}

<div>{prettyAmount}</div>

Whenever currency or amount changes, the output of prettyAmount will be changed as well.

[Vue.js] Can't call child window functions

there is this vue.js page which opens a child window one using following line;

this.presentation = window.open(
this.$router.resolve({name:’presentation’}).href,
‘child window’,
‘width=auto,height=auto’
);

This works like a charm, but now I need to call it’s methods.
I tried to accessing them like so.
Parent:

this.presentation.setPage(0);

Child:

export default {
name: ‘Presentation’,
data() {
return {
page: null
}
},
methods: {
setPage(_page) {
this.page = _page;
}
}

This throws following error.

TypeError: “this.presentation.setPage is not a function”

Why can’t I call child methods? How can I fix this?

Solution :

First, from the window.open() documentation:

windowName

… The name should not contain whitespace. …

Return value:

A Window object representing to the newly created window.

the this.presentation contains Window object, not the vue.js object. Of course, it doesn’t have setPage() method.

Perhaps, something like that could work (in the child component):

{
mounted() {
window.setPage = (page) => this.setPage(page);
}
}

[Vue.js] How to import a js class in main.js file of a vue.js project and use it in all the components instead of importing in each component?

there is written some JS classes that I would like to import in the app.js/main.js file of my vue.js project so that I can instantiate them in the components. Right now when having to import the same JS class in all the components where I need the class individually.

I’ve tried the import in the main.js file but the components don’t recognize it.

in the main.js file, when importing like as follows

import Permissions from ‘./Permissions’

However, when to instantiate the Permissions class in my component like

data() {
permissions: new Permission({
some object properties…
})
}

the component doesn’t know what Permissions is.

How do I let the component know what Permissions class is?

Solution :

To do it in the vue.js way, you can create the own plugin or mixin. See detailed instructions here

So, you can create a permissions plugin in permissions-plugin.js

import Permissions from ‘./Permissions’

const PermissionsPlugin = {
install(Vue, options) {
// This adds the $getPermissions method to all instances
Vue.prototype.$getPermissions = function(properties) {
return new Permission({
some object properties…
})
}
}
};

Then you have to tell vue.js to use the plugin:

import vue.js from ‘vue’
import PermissionsPlugin from ‘./permissions-plugin.js’
import App from ‘./App.vue’

// The plugin is loaded here.
Vue.use(PermissionsPlugin)

new Vue({
el: ‘#app’,
render: h => h(App)
});

And lastly now from any component you should be able to use the function like:

this.$getPermissions(properties)

[Vue.js] how to make dynamic v-if when render in component Vue js?

how to make v-if when rendering to another component to render fast ? there is some case , when when going to login and after success my nabvar component doest change after it finished, i should manually reload it on my client to get logout button and it is same also when i delete , i should manually to reload tho i already put :key on that component

here is my component in my login.vue.js page

goLogin() {
if (!this.input || !this.password) {
this.$swal.fire({
type: ‘error’,
text: `please enter the email/username and password`,
});
} else {
const client = {
input: this.input,
password: this.password,
};
this.$axios
.post(‘/api/user/login’, client)
.then(({
data
}) => {
localStorage.setItem(‘token’, data.token);
// vm.$forceUpdate();
localStorage.setItem(‘role’, data.tryingLogin.role);
this.$swal.fire({
type: ‘success’,
text: `successfully login`,
});
if (data.tryingLogin.role === ‘admin’) {
this.$router.replace({
path: ‘/admin’
});
} else {
this.$router.push({
path: ‘/‘
});
}
})
.catch(err => {
this.$swal.fire({
type: ‘error’,
text: err.response.data.error,
});
});
}

and on my Header.vue.js component, there is isLogin props, and i check by if localStorage.getItem(“token”) i close the button login and register on navbar header.vue.js and it should show logout button if client has token, but it was not, after succesfuly login, i should reload it to get the button logout showing

how to force it to be changed quickly ? to swap show and hide button login and logout ??

i also make props to check login on my App.vue.js and i use all hooks lifecyly to swap login button ans logout , it doesnt changed at all, :(

and it happends when i delete my list also, i should reload it :(
i hope you guys could give me some help and trick for solve this problem :D

Solution :

To share state between different components the best choice would be to use a state management library like Vuex: https://vuex.vuejs.org

You create a store which holds information on whether the user is logged in or not:

const store = new Vuex.Store({
state: {
isLoggedIn: false
},
mutations: {
TOGGLE_LOGIN_STATUS: (state) => {
state.isLoggedIn = !state.isLoggedIn;
}
}
})

When you successfully log in, you change the isLoggedIn flag:

store.commit(‘TOGGLE_LOGIN_STATUS’);

And you can fetch this status from the store in any of the components (it’s also reactive, so changes reflect in all of the components) - it has to be a computed property:

computed: {
isLoggedIn() { return store.state.isLoggedIn; },
}

You can now use isLoggedIn in the v-if to display a logout button. Just remember to either import the store in the components or make it global (everything you need is in the Vuex’s docs).

Another way is using an event bus.

/src/event-bus.js

import vue.js from ‘vue’;
export const EventBus = new Vue();

Import it in the Login component.

import EventBus from ‘@/event-bus’;

After getting the token and successfully logging in, emit an event:

EventBus.$emit(‘logged-in’, true);

Now import EventBus in a component that’s receiving the event (the component with logout button) and place a listener in the mounted hook:

mounted() {
EventBus.$on(‘logged-in’, payload => {
this.isLoggedIn = payload;
})
}

[Vue.js] Vuetify layout with scrollbar

there is a problem I can’t solve in vue.js and vuetify. there is 2 rows, and the upper row is fixed size, because the data there is fix. But in the 2nd row there is 2 columns which are data tables, and the data can be long, but to display all, not just a few lines. So to achieve, when the lower row become higher than the height of the window a scrollbar appear just in the v-flex/v-card.

Here’s the codepen:
https://codepen.io/anon/pen/mgKERm

<div id=”app” style=”height:100vh”>
<v-container fill-height>
<v-layout column>
<v-flex style=”background-color:red” fill-height>
<v-card class=”ma-3”>
<v-data-table :items=”items” hide-actions>
<template v-slot:items=”props”>
<td>{props.item.name}</td>
<td>{props.item.value}</td>
</template>
</v-data-table>
</v-card>
</v-flex>
<v-flex xs12>
<v-layout row fill-height>
<v-flex xs6 style=”background-color:blue” fill-height>
<v-card class=”ma-3”>
<v-data-table :items=”longerItem” hide-actions>
<template v-slot:items=”props”>
<td>{props.item.name}</td>
<td>{props.item.value}</td>
</template>
</v-data-table>
</v-card>
</v-flex>
<v-flex xs6 style=”background-color:green” fill-height>
<v-card class=”ma-3”>
<v-data-table :items=”longerItem” hide-actions>
<template v-slot:items=”props”>
<td>{props.item.name}</td>
<td>{props.item.value}</td>
</template>
</v-data-table>
</v-card>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-container>
</div>

The other problem is that it’s not responsive. The 2nd row 2nd column doesn’t go under the 2nd row 1st column when resizing.

Can someone help me with that?

Thanks!

Solution :

You can add overflow:auto to line 14 of the code. I hope I got the question right. (Or you can add a class to the css and use that instead of using style directly)

<v-flex xs12 style=”overflow:auto”>