link1507 link1508 link1509 link1510 link1511 link1512 link1513 link1514 link1515 link1516 link1517 link1518 link1519 link1520 link1521 link1522 link1523 link1524 link1525 link1526 link1527 link1528 link1529 link1530 link1531 link1532 link1533 link1534 link1535 link1536 link1537 link1538 link1539 link1540 link1541 link1542 link1543 link1544 link1545 link1546 link1547 link1548 link1549 link1550 link1551 link1552 link1553 link1554 link1555 link1556 link1557 link1558 link1559 link1560 link1561 link1562 link1563 link1564 link1565 link1566 link1567 link1568 link1569 link1570 link1571 link1572 link1573 link1574 link1575 link1576 link1577 link1578 link1579 link1580 link1581 link1582 link1583 link1584 link1585 link1586 link1587 link1588 link1589 link1590 link1591 link1592 link1593 link1594 link1595 link1596 link1597 link1598 link1599 link1600 link1601 link1602 link1603 link1604 link1605 link1606 link1607 link1608 link1609 link1610 link1611 link1612 link1613 link1614 link1615 link1616 link1617 link1618 link1619 link1620 link1621 link1622 link1623 link1624 link1625 link1626 link1627 link1628 link1629 link1630 link1631 link1632 link1633 link1634 link1635 link1636 link1637 link1638 link1639 link1640 link1641 link1642 link1643

[Vue.js] Input binding in v-for

to bind values from input radio button generated by v-for.

there is tried use v-model to bind them with variables question_1, question_2, question_3 in data().

<template>
<div id=”radioButtons”>
<div v-for=”(question_obj, index) in questions” :key=”index” class=”form-group form-radio”>
<span>{ question_obj.question } { question_obj.variable }</span>
<br>
<label>
<input type=”radio” :name=”question_obj.variable” v-model=”question_obj.variable” value=”yes” >
<span>Yes</span>
</label>
<label>
<input type=”radio” :name=”question_obj.variable” v-model=”question_obj.variable” value=”no” >
<span>No</span>
</label>
</div>
</div>
</template>

<script>

export default {
name: ‘radioButtons’,
data () {
return {
question_1: ‘’,
question_2: ‘’,
question_3: ‘’,
questions: [
{ question: ‘Question 1’, variable: ‘question_1’},
{ question: ‘Question 2’, variable: ‘question_2’},
{ question: ‘Question 3’, variable: ‘question_3’},
]
}
}
}

</script>

<style>
</style>

I would like the value to be saved in data () after selecting the radio button.

Solution :

Use index in v-for for v-model changes so it changes question object properties, not their instance:

new Vue({
el: ‘#app’,
data () {
return {
//question_1: ‘’, //don’t need question_1, 2 and 3
// question_2: ‘’,
// question_3: ‘’,
questions: [
{ question: ‘Question 1’, variable: ‘no’}, //notice that there is stored default values in question. Also consider renaming variable to answer to preserve good semantics.
{ question: ‘Question 2’, variable: ‘yes’},
{ question: ‘Question 3’, variable: ‘no’},
]
}
},

});
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id=”app”>
<div id=”radioButtons”>
<div v-for=”(question_obj, index) in questions” :key=”index” class=”form-group form-radio”>
<span>{ question_obj.question } { question_obj.variable }</span>
<br>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”questions[index].variable” value=”yes” :checked=”question_obj.variable == ‘yes’”>
<span>Yes</span>
</label>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”questions[index].variable” value=”no” :checked=”question_obj.variable == ‘no’”>
<span>No</span>
</label>
</div>
</div>

</div>

Note: There is no need to store answers in question_1, question_2, question_3, since you might have more than 3 questions, and it won’t be efficient.
Better way is to store answer in variable property value.

So in component it will look like this:

<template>
<div id=”radioButtons”>
<div v-for=”(question_obj, index) in questions” :key=”index” class=”form-group form-radio”>
<span>{ question_obj.question } { question_obj.variable }</span>
<br>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”questions[index].variable” value=”yes” :checked=”question_obj.variable == ‘yes’”>
<span>Yes</span>
</label>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”questions[index].variable” value=”no” :checked=”question_obj.variable == ‘no’”>
<span>No</span>
</label>
</div>
</div>
</template>

<script>

export default {
name: ‘radioButtons’,
data () {
return {
//question_1: ‘’, //don’t need question_1, 2 and 3
// question_2: ‘’,
// question_3: ‘’,
questions: [
{ question: ‘Question 1’, variable: ‘no’}, //notice that there is stored default values in question. Also consider renaming variable to answer to preserve good semantics.
{ question: ‘Question 2’, variable: ‘yes’},
{ question: ‘Question 3’, variable: ‘no’},
]
}
},
}

</script>

<style>
</style>

Solution 2:

Try this code.

export default {
name: ‘radioButtons’,
data () {
return {
radio_data: {
‘question_1’: ‘’,
‘question_2’: ‘’,
‘question_3’: ‘’
},
questions: [
{ question: ‘Question 1’, variable: ‘question_1’},
{ question: ‘Question 2’, variable: ‘question_2’},
{ question: ‘Question 3’, variable: ‘question_3’}
]
}
},
}

<template>
<div id=”radioButtons”>
<div v-for=”(question_obj, index) in questions” :key=”index” class=”form-group form-radio”>
<span>{ question_obj.question } { question_obj.variable }</span>
<br>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”radio_data[questions[index].variable]“ value=”yes” :checked=”question_obj.variable == ‘yes’”>
<span>Yes</span>
</label>
<label>
<input type=”radio” :name=”‘question-‘ + index” v-model=”radio_data[questions[index].variable]“ value=”no” :checked=”question_obj.variable == ‘no’”>
<span>No</span>
</label>
</div>
</div>
</template>

Solution 3:

Store the key, question, and answer in the same object in the array of questions. If you want to get the selected values as an object, use a method to reduce them into an appropriate value. In the example code below I’ve included such a method, as well as live JSON output to see the result.

<template>
<div id=”radioButtons”>
<div v-for=”row in questions” :key=”row.key” class=”form-group form-radio”>
<span>{ row.question } { row.key }</span>
<br>
<label>
<input type=”radio” :name=”row.key” v-model=”row.answer” value=”yes” >
<span>Yes</span>
</label>
<label>
<input type=”radio” :name=”row.key” v-model=”row.answer” value=”no” >
<span>No</span>
</label>
</div>
<pre>{ JSON.stringify(getAnswers(), null, 2) }</pre>
</div>
</template>

<script>
export default {
name: ‘radioButtons’,
data () {
return {
questions: [
{ key: ‘question_1’, question: ‘Question 1’, answer: null },
{ key: ‘question_2’, question: ‘Question 2’, answer: null },
{ key: ‘question_3’, question: ‘Question 3’, answer: null }
]
}
},
methods: {
getAnswers () {
return this.questions.reduce((acc, cur) => {
acc[cur.key] = cur.answer
return acc
}, {})
}
}
}
</script>

[Vue.js] vue-router Optional fixed + path parameter

to have one route object for the following scenarios:

/a/123/b
/b

What there is tried, is:

{
path: ‘(a/:a)?/b’,

}

This seems to work when testing the path on the Express route tester, but only for path-to-regexp version 0.1.7. Any version above that will escape special characters.

In what way is this possible with the new version of path-to-regexp that vue-router uses?

Solution :

Express Router and vue.js Router are different, but if what you mean is you want to create a route with dynamic url, then perhaps you can use named routes from https://router.vuejs.org/guide/essentials/named-routes.html

For example:

const router = new VueRouter({
routes: [
{
path: ‘(a/:a)?/b’,
name: ‘a’,
component: SomeComponent
}
]
})

Then the navigation to SomeComponent should have something like:

<router-link :to=”{ name: ‘a’, params: { a: 123 }”>SomeComponent</router-link>

[Vue.js] Animation in modal window using Vue.js doesn't work

I’m using Vue.js with Laravel and made modal window. All works well, there is no [vue.js warn] indicated, but animation not working, i changed CSS many times.

I’m new to vue.js and trying use this tutorial but it doesnt worked to me https://vuejs.org/v2/guide/transitions.html

View.php

<div id=”modal” >
<!– app –>
<a id=”show-modal” @click=”showModal = true; login = true; register = false”>Login</a>
<modal v-if=”showModal” @close=”showModal = false”>
<div slot=”body”>
<div id=”login” v-show=”login”>
@include(‘login-form’)
</div>
<div id=”register” v-show=”register”>
@include(‘register-form’)
</div>
</div>
</modal>
</div>

app.js

new Vue({
el: ‘#modal’,
data() {
return {
showModal: false,
login: false,
register: false,
}
},
});

Modal.component

<template>
<transition name=”slide-fade” mode=”out-in”>
//–
</transition>
</template>

<script>
export default {
name: ‘modal’,

methods: {
close() {
this.$emit(‘close’);
},
show() {
this.$emit(‘show’);
},
},
};

</script>

UPD — this is CSS

.modal-mask {
position: fixed;
z-index: 99999;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
display: table;
transition: all 1s ease;
}

.modal-wrapper {
display: table-cell;
vertical-align: middle;
transition: all 1s ease;
}

.modal-container {
width: 700px;
margin: 0 auto;
transition: all 1s ease;
}

.slide-fade-enter-active {
transition: all 1s ease;
}
.slide-fade-leave-active {
transition: all 1s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to {
transform: translateX(10px);
opacity: 0;
}

Solution :

You may need to wrap you actual modal in the transition and remove it from the modal component like this:

View

<div id=”modal” >
<!– app –>
<a id=”show-modal” @click=”showModal = true; login = true; register = false”>Login</a>
<transition name=”slide-fade” mode=”out-in”>
<modal v-if=”showModal” @close=”showModal = false”>
<div slot=”body”>
<div id=”login” v-show=”login”>
@include(‘login-form’)
</div>
<div id=”register” v-show=”register”>
@include(‘register-form’)
</div>
</div>
</modal>
</transition>
</div>

Example CSS

/* Enter and leave animations can use different */
/* durations and timing functions. */
.slide-fade-enter-active {
transition: all .3s ease;
}
.slide-fade-leave-active {
transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active below version 2.1.8 */ {
transform: translateX(10px);
opacity: 0;
}

[Vue.js] How to connect nodemailer to a Vue.js and Netlify app using Lambda Functions

there is a static website on Netlify built with Vue.js and there is a specific need to capture x-www-form-urlencoded data being sent from a contact route.

Because it’s a spa and dynamically rendered form there is added this in both the index.html (to pre-render and allow Netlify to see the form on load)

public/index.html & src/views/Contact.vue

<form
netlify-honeypot=”bot-field”
name=”contact”
data-netlify=”true” hidden>

<input name=”bot-field” />
<input type=”text” name=”name” />
<input type=”email” name=”email” />
<input type=”text” name=”subject” />
<textarea rows=”5” name=”message”></textarea>

</form>

The Contact view:

<form
netlify-honeypot=”bot-field”
name=”contact” method=”post”
data-netlify=”true”
@submit.prevent=”handleSubmit”>

<input type=”hidden” name=”form-name” value=”contact” />
<p style=”opacity: 0;”>
<label>Dont fill this out if you’re human: <input name=”bot-field” /></label>
</p>
<p>
<label>the Name: <input v-model=”form.name” type=”text” name=”name” /></label>
</p>
<p>
<label>the Email: <input v-model=”form.email” type=”email” name=”email” /></label>
</p>
<p>
<label>the Subject: <input v-model=”form.subject” type=”text” name=”subject” /></label>
</p>
<p>
<label>Message: <textarea v-model=”form.message” rows=”5” name=”message”></textarea></label>
</p>
<p>
<button>Send</button>
</p>

</form>

The data properties in the component are modelled and the method to POST off the data is as follows:

export default {
name: ‘contact’,
data: () => ({
form: {
name: ‘’,
email: ‘’,
subject: ‘’,
message: ‘’,
},
}),
methods: {
encode (data) {
return Object.keys(data)
.map(
key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`,
)
.join(‘&’);
},
handleSubmit () {
const axiosConfig = {
header: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ },
};
axios.post(
‘/‘,
this.encode({
‘form-name’: ‘contact’,
…this.form,
}),
axiosConfig,
)
.then(() => console.log(‘success’))
.catch(e => console.error(e));
},
},
};

The next part of the system is the lambda function run by Netlify. Netlify allows a submission-created function every time the application receives a form submission. All you have to do is create a directory in the root of the project with the submission-created.js file in it. This directory needs to be specified in netlify.toml so Netlify knows where to look for the funcitons.

Another caveat is that if the function requires dependencies, you need to zip the folder with the node_modules included. I automate this in package.json with bestzip dependency.

package.json

“scripts”: {
“serve”: “vue-cli-service serve”,
“build”: “vue-cli-service build”,
“lint”: “vue-cli-service lint”,
“zip”: “cd functions/submission-created && bestzip ../../functions-build/submission-created.zip *“,
“clean”: “rm -rf functions-build && mkdir functions-build”,
“prebuild”: “npm run clean && npm run zip”
}

As you can see, the way I handle this is by writing the source of the function in functions/submission-created/submission-created.js I also have a functions-build directory which is the one specified in netlify.toml, that will contain the zipped up submission-created folder.

Basically, I npm init -y the functions/submission-created directory and npm install nodemailer, when prebuid runs, it deletes the current functions-build and re-creates it followed by zipping the functions into the directory with it’s dependencies.

Here is the netlify.toml

[build]
functions = “./functions-build”

Finally, where the important code lies, is the submission-created.js file:

exports.handler = function(event, context, callback) {
const nodemailer = require(‘nodemailer’);
const querystring = require(‘querystring’);
const payload = querystring.parse(event.body);
const { name, email, subject, message } = payload;

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: “xxx”,
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: ‘xxx’, // generated ethereal user
pass: ‘xxx’ // generated ethereal password
},
tls: {
rejectUnauthorized: false,
},
});

// setup email data with unicode symbols
let mailOptions = {
from: `“website enquiry “ <${email}>`, // sender address
to: “admin@xxx.xx, enquiry@xxx.xx“, // list of receivers
subject: `${subject} `, // Subject line
text: `name: ${name}, \n email: ${email}, \n message: ${message}\n`, // plain text body
};

// send mail with defined transport object
transporter.sendMail(mailOptions)
.then(() => {
callback(null, { statusCode: 200, body: ‘Success’ });
})
.catch(e => callback(e, { statusCode: 500, body: ‘Error sending email’ }));

};

The main problem

The form is recorded in the submissions on Netlify. The problem lies in the function:

In development (Hosting lambda function locally using netlify-lambda) I receive the properties as entered on the site.

In production, the properties are undefined. And the full event object is not logged to the console in functions.

Solution :

The answer lies in the event param in production vs in development.

the fix:

// How to get post parameters in production
exports.handler = function(event, context, callback) {
const payload = JSON.parse(event.body).payload;
const { name, email, subject, message } = payload;
}

[Vue.js] How to use Vue on click to toggle/ deactive an active html class?sylesheet

when trying this peace of code to toggle class by vue.js on-click event. But not working and showing bunch or errors in console. Can you help me ?

<div id=”app5”>
<h1>Dynamic CSS</h1>
<h2>Example 1</h2>

<div
v-bind:class=”{available: value}”
v-on:click=”available = !available”>
<span>Click</span>

</div>
</div>

var app5=new Vue({
el:’#app5’,
data:{
value: true,
nearby:false
}
});

sylesheet

span{
background:red;
color: #fff;
}

.available span{
background: green;
}

when expecting the span background will initially green but red after click.

Solution :

In the click handler, you’re trying to toggle the available variable, which is actually the name of the css class. The syntax for class binding is the following: v-bind:”{classtotoggle: variable}”.

So you should have written:

<div v-bind:class=”{available: value}” v-on:click=”value = !value”>
<span>Click</span>
</div>

As an advice, I’d always use a function to handle event (v-on directive), It makes it easier to add behaviour in the future.

Hope that helps,

Solution 2:

You have to toggle value onclick v-on:click=”value = !value” check below code.

var app5=new Vue({
el:’#app5’,
data:{
value: true,
nearby:false
}
});
span{
background:red;
color: #fff;
}

.available span{
background: green;
}
<script src=”https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id=”app5”>
<h1>Dynamic CSS</h1>
<h2>Example 1</h2>

<div
v-bind:class=”{available: value}”
v-on:click=”value = !value”>
<span>Click</span>

</div>
</div>

[Vue.js] Changes to properties in mounted not triggering computed in VueJS

there is a VueJS component which contains a button whose class and text are computed properties and changes every time the button is clicked. They are changing fine as long as I click on the button once it is loaded. I wanted to store the state in localStorage and if I reload the page set the text and class based on the value stored. The value of ordered is changing but the button text and class are not reflecting that in UI. Does anyone have any suggestion as to what I may be doing wrong? Following is the source

<template>
<div class=”main-view”>
<button type=”button” :class=”order_button_style” @click=”on_order_button_click()”>
{ order_button_text }
</button>
</div>
</template>

<script>
export default {
name: “FoodComponent”,
props: {
item: Object
},
methods: {
on_order_button_click() {
this.item.ordered = !this.item.ordered;
localStorage.setItem(this.item.id, this.item.ordered);
}
},
mounted() {
var storedState = localStorage.getItem(this.item.id);
if (storedState) {
this.item.ordered = storedState;
}
},
computed: {
order_button_text() {
return this.item.ordered === true ? “Ordered” : “Order”;
},
order_button_style() {
return this.item.ordered === true
? “button ordered-button”
: “button unordered-button”;
}
}
};
</script>

Solution :

What you will get from the local storage is a string. In mounted, ordered property will be a string instead of a boolean so you order_button_text computed property condition will never be true. To fix this you can just convert storedState property to a boolean :

mounted() {
const storedState = localStorage.getItem(this.item.id) === ‘true’;
if (storedState) {
this.item.ordered = storedState;
}
},

[Vue.js] How can I break my Vuex actions into multiple files and still use `dispatch`?

there is broken my actions into multiple files to make my project more maintainable and extensible. Trying to dispatch from one action to another, however, is not working.

My file tree looks like this:

store.js
actions
|–actions.js
|–createShape.js
|–addShape.js

My store.js looks like:

import actions from ‘./actions/actions’

const PlaypadStore = {
namespaced: true,
state: {
localState: ‘’
},
actions: {
…actions,
},
}

My actions.js folder has the following:

import CREATE_SHAPE from ‘./createShape’;
import ADD_SHAPE from ‘./addShape’;

export default {
CREATE_SHAPE,
ADD_SHAPE,
}

The problem is trying to dispatch ADD_SHAPE from CREATE_SHAPE. My createShape.js looks like the following:

const CREATE_SHAPE = ({ state, dispatch }) => {
return dispatch(‘ADD_SHAPE’)
}

export default CREATE_SHAPE;

But it returns me this:

[vuex] unknown local action type

The question is this: how can I break my actions into multiple files, but still be able to dispatch actions from one to another?

Solution :

you need to let Vuex know that actions.js, createShape.jsand addShape.jsare “modules” of the store for this to work.
You can read more about it in the Vuex Modules documentation.

Basically you need an index.js file declaring the modules at the root of the store. That should look like this:

import actions from “./actions”;
import createShape from “./createShape”;
import addShape from “./addShape”;

Vue.use(Vuex);

export default new Vuex.Store({
modules: {
actions,
createShape,
addShape
}
});

At this point the dispatch call should work, UNLESS it comes from another vuex store module, in that case just specify “root = true” as they pointed out here.

[Vue.js] Translate header of table in Bootstrap-Vue.js

I’m already trying to translate my table header in a vue.js component for a few nights, but it doesn’t work for me. Probably this is due the fact that I’m new to Vue.js and probably that I’m forgetting something but I’m not able to find the clue. The translation within the HTML wording is working fine, but as soon as I would like to translate an attribute within the script tag (e.g. data attributes) I’m getting console errors that certain fields cannot be found.

What I did, first I initialized the i18n component within the main.js

import vue.js from ‘vue’
import Bootstrapvue.js from ‘bootstrap-vue’
import App from ‘./App’
import router from ‘./router’
import axios from ‘./api’
import VueAxios from ‘vue-axios’
import VueI18n from ‘vue-i18n’

Vue.use(BootstrapVue)
Vue.use(VueAxios, axios)
Vue.prototype.$axios = axios;

Vue.use(VueI18n)

// Ready translated locale messages
const messages = {
en: require(‘./locales/en_GB.json’),
nl: require(‘./locales/nl_NL.json’)
}

// Create VueI18n instance with options
const i18n = new VueI18n({
locale: ‘nl’, // set locale
fallbackLocale: ‘en’,
messages // set locale messages
})

// TODO load messages async, otherwise all messages will be loaded at once: http://kazupon.github.io/vue-i18n/guide/lazy-loading.html

/* eslint-disable no-new */
new Vue({
el: ‘#app’,
router,
i18n,
template: ‘<App/>’,
components: {
App
}
})

Then within my script tag of the Users component I’m trying to translate the table header that is defined in there. However for some reason I’m getting console errors like TypeError: “o is undefined”.

data: () => {
return {
items_data: [],
fields: [
{key: this.$i18n.t(‘next’)}, //<– Translate table header values
{key: ‘name’},
{key: ‘registered’},
{key: ‘role’},
{key: ‘status’}
],
currentPage: 1,
perPage: 5,
totalRows: 0
}

See full file here below:

<template>
<b-row>
<b-col cols=”12” xl=”6”>
<transition name=”slide”>
<b-card :header=”caption”>
<b-table :hover=”hover” :striped=”striped” :bordered=”bordered” :small=”small” :fixed=”fixed” responsive=”sm” :items=”items” :fields=”fields” :current-page=”currentPage” :per-page=”perPage” @row-clicked=”rowClicked”>
<template slot=”id” slot-scope=”data”>
<strong>{data.item.id}</strong>
</template>
<template slot=”name” slot-scope=”data”>
<strong>{data.item.name}</strong>
</template>
<template slot=”status” slot-scope=”data”>
<b-badge :variant=”getBadge(data.item.status)”>{data.item.status}</b-badge>
</template>
</b-table>
<nav>
<b-pagination size=”sm” :total-rows=”5” :per-page=”perPage” v-model=”currentPage” :prev-text=”$t(‘previous’)” :next-text=”$t(‘next’)” hide-goto-end-buttons/>
</nav>
</b-card>
</transition>
</b-col>
</b-row>
</template>

<script>
var usersData = null;
export default {

name: ‘Test Users’,
props: {
caption: {
type: String,
default: ‘Users 2’
},
hover: {
type: Boolean,
default: true
},
striped: {
type: Boolean,
default: true
},
bordered: {
type: Boolean,
default: false
},
small: {
type: Boolean,
default: false
},
fixed: {
type: Boolean,
default: false
}
},
data: () => {
return {
items_data: [],
fields: [
{key: this.$i18n.t(‘next’)}, //<– Translate table header values
{key: ‘name’},
{key: ‘registered’},
{key: ‘role’},
{key: ‘status’}
],
currentPage: 1,
perPage: 5,
totalRows: 0
}
},
mounted() {
this.axios.getAll()
.then(response => {
//this.$log.debug(“Data loaded: “, response.data)
this.items_data = response.data
}).catch(error => {
//this.$log.debug(error)
this.error = “Failed to load todos”
})
},
computed: {
items: function () {
return this.items_data;
}
},
methods: {
getBadge (status) {
return status === ‘Active’ ? ‘success’
: status === ‘Inactive’ ? ‘secondary’
: status === ‘Pending’ ? ‘warning’
: status === ‘Banned’ ? ‘danger’ : ‘primary’
},
getRowCount (items) {
return items.length
},
userLink (id) {
return `users/${id.toString()}`
},
rowClicked (item) {
const userLink = this.userLink(item.id)
this.$router.push({path: userLink})
}

}
}
</script>

<style scoped>
.card-body >>> table > tbody > tr > td {
cursor: pointer;
}
</style>

I would be very thankful when someone could help me to tell how I should translate these type of texts. I tried to find my solution via Google, but according to Google this is more or less how it should work.

Solution :

According to the documentation:

The fields prop is used to customize the table columns headings, and
in which order the columns of data are displayed. The field object
keys are used to extract the value from each item row…

meaning in the fields property, the key’s value needs to match the items keys.
For example, first_name:

fields: [
{ key: ‘first_name’}
],
items: [
{ first_name: ‘John’ },
{ first_name: ‘Jane’ }
]

If you want to customize the headers, like translated titles, you can use label:

fields: {
{
next: { label: this.$i18n.t(‘next’) },
name: { label: this.$i18n.t(‘name’) },
registered: { label: this.$i18n.t(‘registered’) },
role: { label: this.$i18n.t(‘role’) },
status: { label: this.$i18n.t(‘status’) }
}
}

[Vue.js] vuejs - show alert and redirect after submiting axios form

there is a form which is working fine and inserting data but if the user press the submit button 10 times it insert the data 10 times so to redirect the user to another page and show him the success message or error . here when using axios as below there is added the then resoponse and catch error but its not displaying i think there is to show in html some how:

reserve() {
// this.form.post(‘../api/comment’)
axios.post(‘../api/reserve’,{
property_id:1,
reserve_start:this.date,
reserve_end:this.date2,
}).then(response => {
self.message = ‘Data is entered’
})
.catch(error => {
self.message = ‘Error’
})

and here is my form markup :

<form @submit.prevent=”reserve()” id=”myForm” class=”m-form m-form–fit m-form–label-align-right m-form–group-seperator-dashed”>

Solution :

It’s pretty straight forward to redirect in a method after an axios call.

something like this:

reserve() {
// this.form.post(‘../api/comment’)
axios.post(‘../api/reserve’,{
property_id:1,
reserve_start:this.date,
reserve_end:this.date2,
}).then(response => {
this.$router.push(‘/routeToGoTo’)
})
}
.catch(error => {
self.message = ‘Error’
})

You could put an alert before the router.push and this will stop everything until it is dimissed. So the alert would show, user clicks ok, page redirects.

alert(“Something was done.”)

[Vue.js] Vue How to refresh new data?

when using vue.js Components in my blade file. Whenever I need to ‘refresh’ my customer object, I emit an event to the parent (shown below) and customer is refreshed and any props it passed to children will be shown with their updated values.
This is all well and good so far but when now using some PHP values. when passing a prop automatic-payments-enabled and it’s using a php value. How can there is that value refresh after making an API call that changes it?

Blade file

<div id=”app”>

<Account
:customer=”customer”
:automatic-payments-enabled={!! json_encode($customer->automaticPaymentsEnabled()) !!}
\>
</div>

app.js

Vue.component(‘Account’,
require(‘./components/Account.vue’).default);

new Vue({
el: “#app”,
data() {
return {
customer: null
}
}
mounted() {
this.getCustomer();
}
methods: {
getCustomer: function() {
//api call to server
this.customer = response.data
}
}
}

Solution :

I suppose $customer is actually a Model. If so, you can use

$customer->fresh()->automaticPaymentsEnabled()