<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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
指令的周期
<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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39