<template>
<div>
<div v-for="(emp, i) in emps" :key="i">
<span>{{ emp.ename }}</span>
<span>{{ emp.birthday }}</span>
<span v-date="emp.birthday"></span>
</div>
</div>
</template>
<script>
export default {
directives: {
date(el, bindings) {
var d = new Date(bindings.value)
var year = d.getFullYear()
var month = d.getMonth() + 1
var day = d.getDate()
el.innerText = `${year}/${month}/${day}`
},
},
data() {
return {
emps: [
{ ename: '壮壮', birthday: 626014629000 },
{ ename: '边边', birthday: 636025629000 },
{ ename: '小海', birthday: 616021629000 },
{ ename: '浩浩', birthday: 606022429000 },
],
}
},
}
</script>
<style lang="scss" scoped></style>
指令的周期
<template>
<div>
<input type="text" />
<br />
<input type="text" v-focus />
<br />
<input type="text" />
</div>
</template>
<script>
export default {
directives: {
focus: {
inserted(el) {
el.focus()
},
},
},
}
</script>
<style lang="scss" scoped></style>
|