# [Vue.js] Why laravel vue js this.form.post(url) automatically converting into get method Subscribe to RSS

vue.js.js get method is working instead of post method.
but in localhost its working perfectly.
Only facing this issue when i’m upload project into server

export default {
data(){
return {
form: new Form({
company_name : ‘’,
contact_name : ‘’,
number : ‘’,
keyword_or_comment : ‘’,
attachment : ‘’
})
}
},
methods: {
createPhoneBook(){
this.$Progress.start(); const url = ${API_URL}/api/apiurl/;
this.form.post(url)
.then(() => {
toast.fire({
type: ‘success’,
})
this.$Progress.finish(); }) .catch(() => { this.$Progress.fail()
})
}
},
created() {
}
}

Anyone can help me,

### Solution :

I will suggest you to use axios Ajax request. this is highly recommended for vue.js js.

like:

axios.post(location.pathname, { body: this.body })
.catch(error => {
flash(error.response.data, “danger”);
})
.then(({ data }) => {
this.body = “”;

});

# [Vue.js] How to get the event info in Vue.js? Subscribe to RSS

I’m trying to use vue.js Devtools to debug my App and I was wondering how to retrieve the info I see after an event.

<l-marker v-for=”marker in markers”
:lat-lng=”marker.position”
:key=”marker.id”
:draggable=true
@dragend=”dragend”>
</l-marker>

My event is @dragend=”dragend”,How can I get the lat and lng values?

Edit: Is this correct?

dragend: function(event){

console.log(event.target._latlng);
}

### Solution :

if you edit the attribute in

:lat-lng.sync=”marker.position”

you will have the position always updated within the property marker.position, without using @dragend event

# [Vue.js] VUEJS Is it possible to process/modify data retrieved through v-for before displaying? Subscribe to RSS

Hello when extremely new to web application development / javascript in general. Only gave myself crash courses from udemy videos for the past 4 months.

For my web application, when retrieving data from a database through my server-side backend with axios. there is a logRepository Array where the retrieved data is pushed.

data() {
return {
logRepository: [],
}
},
created() {
axios.get(‘/myrestapiroute’, {
‘Authorization’: Bearer ${this.$store.state.token}
},
params: {
userId: this.userId
}
})
.then(res => {
const data = res.data.logs
this.dataCheck = data
for(let key in data) {
const log = data[key]
log.id = key
this.logRepository.push(log)
}
})

On my template, I used v-for to loop through all the retrieved data elements:

<div ….. v-for=”(log,index) in logRepository” :key=”index”>

With the v-for in place, one example of how I display my data as such in a paragraph tag. The format is due to how the data was structured.

<p style=”text-align: justify;”>
{ log.logId.jobPerformed }
</p>

The problem arises when I try to apply styling to the text. As you can see above, I would like to use text-align: justify. I also wanted to keep the whitespace as how it was input by the user through the use of white-space: pre-wrap.

But the problem is these two styles do not work together well. As can be seen below in the picture, if I use justify on its own, it behaves normally (Except that whitespace is lost). However, if I combine both text-align:justify and white-space: pre-wrap, the text end up justified with spacing, but aligned in a weird way.

For short entries, they begin with weird indentation when the starting side should be aligned to the left of the column. The issue appears to be more than simply whitespaces at the start as there is tried .trim() as suggested by a contributor.

I tried to tweak the CSS around, with text-align-last, text-align-start, direction: ltr, pre-tags etc. But it just does not work properly. Suggestions from other SO pages recommended that the data be processed by performing a string replace of all \n to br before displaying.

Is it possible to perform processing for individual data obtained from v-for before displaying or it has to be done to the array using computed property?

Since my data is to be fetched from a database, when confused on how to achieve the pre-processing of data, since my array size will dynamic and differ for each user.

What would be the most optimal way to achieve pre-processing of data before displaying for such case?

This image below is how my Array of Object (logRepository) looks like. The format is largely due to mongoDB schema.
(https://i.imgur.com/7SilcF7.png)

\======= Solution =======

I modified the object variables in my .then block and performed string replace for all \n characters to tags.

https://i.imgur.com/EtLX2tg.png

With that my display no longer requires the “white-space: pre-wrap” styling. However, since I was previously using string interpolation to display my data the tags were treated as plain text.

https://i.imgur.com/zUbNZbI.png

I had to modify the tags to use v-html binding to display the data as htmltext so that would work. The difference can be seen in the last picture.

https://i.imgur.com/sCTsCV4.png

Thanks for helping me on this since when very new to javascript.

### Solution :

There are a number of patterns you could use here to pre-process the data.

Process the data in the then function you have created
Wrap the data in functions within the { … } blocks in the template
Create a component that is used as the element that the v-for loop iterates over which displays a computed value
Use a computed value as the source array of the v-for directive in the main template. This is often done using a processing function mapped to the source data, as in log.map( data => data.logId.jobPerformed.trim()

# [Vue.js] Display objects with the same key in one row Subscribe to RSS

I got this objects

{“key”:[“0114”,”1”,”2013”],”values”:[“279”]},
{“key”:[“0114”,”1”,”2014”],”values”:[“235”]},
{“key”:[“0114”,”1”,”2015”],”values”:[“258”]},
{“key”:[“0114”,”1”,”2016”],”values”:[“274”]},
{“key”:[“0114”,”1”,”2017”],”values”:[“293”]}

0114 is a county in sweden.

1 is symbolizes men

2013… is the years

values is the amount of men born in ex. 2013

to display them like this:

How it looks right now:

How i’m displaying rightnow :

<div class=”tabellWrapper”>
<table class=”kommunerMainWrapper” >
<tr>
<td >Kommun</td>
<th >Kn</th>
<th >2013</th>
<th >2014</th>
<th >2015</th>
<th >2016</th>
<th >2017</th>
</tr>
<tbody class=”kommunerWrapper” >
<template v-for=”(data,index) in selectedLanData”>
<tr v-if=”data.key[1] ===’1’” :key=”index”>
<th class=”kommunerItem kommun”>{data.key[0]}</th>
<th class=”kommunerItem sex” >Mn</th>
<th class=”kommunerItem numbers”>{data.values[0]}</th>
<th class=”kommunerItem numbers”>{data.key[2]}</th>
</tr>
<tr v-else :key=”index”>
<th class=”kommunerItem kommun”>{data.key[0]}</th>
<th class=”kommunerItem sex” >Kvinnor</th>
<th class=”kommunerItem numbers”>{data.values[0]}</th>
<th class=”kommunerItem numbers”>{data.key[2]}</th>
</tr>
</template>
</tbody>
</table>
</div>
</div>

### Solution :

I think you should parse the data array before. If it is a possibility for you, this could be the code:

var source = [
{“key”:[“0114”,”1”,”2013”],”values”:[“279”]},
{“key”:[“0114”,”1”,”2014”],”values”:[“235”]},
{“key”:[“0114”,”1”,”2015”],”values”:[“258”]},
{“key”:[“0114”,”1”,”2016”],”values”:[“274”]},
{“key”:[“0114”,”1”,”2017”],”values”:[“293”]}
];

var parsed = {};

for (var i=0; i<source.length; i++) {
var key = source[i].key;
if (!(source[i].key[0] in parsed)) {
parsed[source[i].key[0]] = {};
}
if (!(source[i].key[1] in parsed[source[i].key[0]])) {
parsed[source[i].key[0]][source[i].key[1]] = {};
}
if (!(source[i].key[2] in parsed[source[i].key[0]][source[i].key[1]])) {
parsed[source[i].key[0]][source[i].key[1]][source[i].key[2]] = 0;
}
parsed[source[i].key[0]][source[i].key[1]][source[i].key[2]] += parseInt(source[i].values);
}

console.log(parsed);

### Solution 2:

You can simply do it with the reduce function as so:

const data = [
{“key”:[“0114”,”1”,”2013”],”values”:[“279”]},
{“key”:[“0114”,”1”,”2014”],”values”:[“235”]},
{“key”:[“0114”,”1”,”2015”],”values”:[“258”]},
{“key”:[“0114”,”1”,”2016”],”values”:[“274”]},
{“key”:[“0114”,”1”,”2017”],”values”:[“293”]}
];

const tableRows = data.reduce((rows, value) => {
let currentRow = rows.find(row => row.region === value.key[0] && row.gender === value.key[1]);
if (!currentRow) {
currentRow = {region: value.key[0], gender: value.key[1]};
rows.push(currentRow);
}
currentRow[value.key[2]] = value.values[0];
return rows;
}, []);

console.log(tableRows);

# [Vue.js] CSS grid - count number of columns (javascript) Subscribe to RSS

there is a CSS grid

.wrapper {
display: grid;
grid-template-columns: repeat(auto-fill, 12.5vw );
grid-template-rows: repeat(auto-fill, 12.5vw );
background-color: black;
grid-auto-flow: row dense;
color: #444;
}

<div class=”wrapper”>
<div class=”box wide tall a”>
</div>
<div class=”box b”>
</div>
<div class=”box c”>
</div>
<div class=”box c”>
</div>
<div class=”box d”>
</div>
<div class=”box e”>
</div>
<div class=”box f”>
</div>
<div class=”box g”>
</div>
<div class=”box h”>
</div>
</div>

And I would like to know the number of columns in my javascript code. is it possible?

EDIT: the reason this is that if there is less than the good amount of items so that it makes a square, these extra items not to be displayed at all.

Thanks a lot!

### Solution :

You can use getElementsByClassName to retrieve all the box divs and get the array length:

var columns = document.getElementsByClassName(‘box’).length

### Solution 2:

I think you are missing the minmax part of the grid-template-columns:
eg grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));

with out it, you will always have 7 columns, and the grid columns wont be responsive and change as page width shrinks/expands.

can see Jen Simmons example page here : Spice Gallery Layout

A Solution that doesnt require any javascript.. but a few media queries..
is to wrap the .wrapper div with a container. and set a max height. per screen break point when every there would be un even images on the last row.
then set the .container overflow-y:hidden;

link to pen here : Hide last row of grid with css

Doing this with javascript you would need to know how many images you have, and what the minmax column widths are. vw units are basicaly width in %. so you would need to do some maths. with a mod function to know how many items are on the last row. and then need a way to hide them.

# [Vue.js] What is jQuery like syntax doing in Vue.js? Subscribe to RSS

I was just going through some Vue.js code HERE and came across the following line of code:

.svg-icon.streak(v-html=”icons.streak”, v-b-tooltip.hover.bottom=”$t(‘streakCounter’)”) There is this jQuery like syntax$t() and i don’t quite understand it , what exactly is this function doing ? where is it coming from ? i see no such function being imported ?

Can somebody explain what this jQuery like syntax is doing ?

### Solution :

This comes from the i18n : https://github.com/HabitRPG/habitica/blob/develop/website/client/libs/i18n.js

// vue.js plugin to globally expose a ‘$t’ method that calls common/i18n.t. // Can be anywhere inside vue.js as ‘this.$t’ or ‘$t’ in templates. And you can find streakCounter here : https://github.com/HabitRPG/habitica/blob/1135ab946e11300c2199c14cb5451f7370ed0b28/website/common/locales/en/tasks.json#L57 (and in other translation file for different languages) # [Vue.js] Error 500 when I try to store data from Vue.JS by Laravel Subscribe to RSS there is an issue with my code. When I try to store data using Vue.JS and Laravel i get error 500 in the console. I’m stuck on it for 6 hours. Controller - DashboardAdvantagesController.php: public function store(Request$request)
{
$request->validate([ ‘icon’=> ‘required’, ‘title’=> ‘required’ ]);$advantage = $request->HomepageAdvantages()->create([ ‘icon’=>$request->icon,
‘title’=> $request->title ]); return response()->json([ ‘advantage’=>$advantage,
]);

}

Model

{
protected $fillable = [ ‘icon’, ‘title’, ‘text’, ]; } API route Route::post(‘/advantages/store’, ‘DashboardAdvantagesController@store’); vue.js Component createAdvantage(){ console.log(this.advantage.icon); console.log(this.advantage.title); axios.post(‘http://127.0.0.1:8000/api/advantages/store', {icon: this.advantage.icon, title: this.advantage.title}) .then(response=>{ this.advantages.push(response.data.advantage); }) .catch(error=>{ console.log(error); }); console.log(response.data.advantage); }, My error: Failed to load resource: the server responded with a status of 500 (Internal Server Error) :8000/api/advantages/store:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error) 2app.js:267 POST http://127.0.0.1:8000/api/advantages/store 500 (Internal Server Error) dispatchXhrRequest @ app.js:267 xhrAdapter @ app.js:118 dispatchRequest @ app.js:706 Promise.then (async) request @ app.js:513 Axios.<computed> @ app.js:533 wrap @ app.js:966 createTask @ app.js:1773 invokeWithErrorHandling @ app.js:9448 invoker @ app.js:9773 original._wrapper @ app.js:15126 ### Solution :$request->HomepageAdvantages()

I’m not sure how you came up with this, as it will only work when you have a macro registered on the Request class. If so, please disregard this comment.

Otherwise, you’ll need to explicitly call the model using HomepageAdvantages::create().

# [Vue.js] Vue \$watch for array of objects Subscribe to RSS

when new to Vue. We are migrating code from dojo to Vue. I was trying to add watch to an Array of objects. My data in which there is to add watch is an array of objects and Objects again can have arrays.

Sample data:

ItemList: [
{
item: {
term: 1,
timing:A
steps: [{}], ( Array )
parameter: [{}] ( Array)

almost 600 values
}
},
{
item: {
term: 2,
timing:B
steps: [{}],
parameter: [{}]

….
….

almost 600 values
}
}
]

In old dojo the code was like this:

for (c = 0; c < itemList.length; c++) {
item=itemList[c];
var itemWatch = item.watch(function(name,oldVal,newVal) {
}
}

//Here the name gives what value of array is changed . I need that for future
//logic. we can add watch on each item.

computed:{
clonedItems: function(){
return JSON.parse(JSON.stringify(this.itemList));
}
},
watch:{

clonedItems:{
deep: true,
handler: function (val, oldVal) {

This I tried which is working fine, but to get to know what value is changed of this will be heavy computation. This array can be of 100 items and each item have 600 items where we have arrays as well.

Please guide what is the best way to achieve the similar functionality what we have.

### Solution :

here is a code from vuejs.org website :

var vm = new Vue({
data: {
a: 1,
b: 2,
c: 3,
d: 4,
e: {
f: {
g: 5
}
}
},
watch: {
a: function (val, oldVal) {
console.log(‘new: %s, old: %s’, val, oldVal)
},
// string method name
b: ‘someMethod’,
// the callback will be called whenever any of the watched object properties change regardless of their nested depth
c: {
handler: function (val, oldVal) { /* … */ },
deep: true
},
// the callback will be called immediately after the start of the observation
d: {
handler: ‘someMethod’,
immediate: true
},
e: [
‘handle1’,
function handle2 (val, oldVal) { /* … */ },
{
handler: function handle3 (val, oldVal) { /* … */ },
/* … */
}
],
// watch vm.e.f’s value: {g: 5}
‘e.f’: function (val, oldVal) { /* … */ }
}
})

https://vuejs.org/v2/api/?#watch

# [Vue.js] Using React.js and Vue.js Together in Laravel Subscribe to RSS

I really want to know, is it possible to using react.js and vue.js next to each other in a laravel? For Example, use ReactJs for admin dashboard and use VueJs for client dashboard. I know it’s technically and logically better to use one of them.
What do you think? Can we use them together?

### Solution :

Yes. It is definitely possible. Polyglot programming is today’s reality. There are a couple of approaches you can take. A most common approach would be that of a micro-frontends.

How you implement micro-frontend is up to you! But in general, you will have two different SPA served on two different routes. You will interlink these two applications using hyperlinks/anchor tags. However, note that, doing something that is a big cost and really meant for very large applications and teams building them.

There are many leaf components like buttons, links, dropdown, etc. which you will end up developing and maintaining for both frameworks. State management, routing, services will be rewritten for each framework. It is incredibly painful to match consistent style guide across frameworks.

Nowadays, if you really need to go ahead with this approach, you can consider using custom-elements for the leaf components. They should work for many SPA frameworks (see the notes). This will help you save the trouble of reinventing the wheel.

Note: React is not very friendly with web-components. It fails on many advanced tests.

# [Vue.js] Creating vue.js mobileapp Subscribe to RSS

to use vue.js for creating mobile app. Advice me please any ways. I know about crdova(phoneGap) but it’s web based app. I listened about vue-native, but there is some troubles with that. May be there is easer ways to create on vue.js?

### Solution :

Vue.js is the perfect framework for creating good looking web interfaces easily. Since you are trying to create a mobile app, we have the following options:

Create responsive web app using vue.js and vuetify. User can open it in the desktop browser as well as mobile browser. If you really want to retrofit into a mobile app, you create a simply android app and use WebView to show the web app
You can create a native app from scratch. Creating a good looking native app would take a huge effort.