Answer the question
In order to leave comments, you need to log in
What is this way of declaring properties in vue?
good afternoon guys,
I recently downloaded the repository with the vue.js library code, and found something interesting there. (Code below)
Tell me, are these ordinary properties and can you work with them the same way in react.js ?
export default {
data: () => ({
title: '',
description: '',
imageUrl: '',
date: moment().unix(),
duration: 3600, // 1 hour
ticketCost: 1e17, // 0.1 ether
maxTickets: 1000,
dialog: false,
showDatePicker: false,
showTimePicker: false,
symbol: defaultSymbol,
timeRule: [v => v.match(timeRegExp) != null || 'Invalid time!'],
maxTicketsRule: [v => v > 0 || 'Invalid amount!']
}),
computed: {
dateInput: {
get: function () {
return moment(this.date * 1000).toISOString().substr(0, 10)
},
set: function (newDate) {
this.date = moment(newDate).unix()
}
},
timeInput: {
get: function () {
return moment(this.date * 1000).format('H:mm')
},
set: function (time) {
if (time.match(timeRegExp)) {
const values = time.split(':')
moment(this.date).minutes(values[0]).seconds(values[1])
}
}
},
durationInput: {
get: function () {
return moment.utc(this.duration * 1000).format('H:mm')
},
set: function (time) {
if (time.match(timeRegExp)) {
const values = time.split(':')
moment.utc(this.duration).minutes(values[0]).seconds(values[1])
}
}
},
ticketCostInput: {
get: function () {
return this.$web3.utils.fromWei(this.ticketCost.toString(), 'ether')
},
set: function (value) {
this.ticketCost = this.$web3.utils.toWei(value.toString())
}
}
},
methods: {
reset: function () {
this.title = this.description = this.imageUrl
this.symbol = defaultSymbol
this.date = moment().unix()
this.duration = 3600
this.maxTickets = 1000
},
close: function () {
this.reset()
this.dialog = false
},
save: async function () {
await this.$store.dispatch('createEvent', [
this.title,
this.description,
this.imageUrl,
this.symbol,
this.ticketCost,
this.date,
this.duration,
this.maxTickets
])
this.close()
}
}
}
Answer the question
In order to leave comments, you need to log in
Everything in the date is reactive
Computed properties, these are calculated properties, read the docs about their caching, not everything is unambiguous there. Methods are pure methods.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question