2022-12-06 17:01:46 +08:00
|
|
|
<template>
|
2023-01-10 10:09:13 +08:00
|
|
|
<span test-id="count">{{count}}</span>
|
2023-01-11 15:50:04 +08:00
|
|
|
<span test-id="id">{{obj.id}}</span>
|
|
|
|
|
<span test-id="title">{{obj.title}}</span>
|
2023-01-10 10:09:13 +08:00
|
|
|
<button test-id="button" @click="click">click</button>
|
2023-01-13 17:42:25 +08:00
|
|
|
<span test-id="tab">{{lineTab}}</span>
|
2023-01-30 11:50:22 +08:00
|
|
|
<el-table
|
|
|
|
|
:data="tableData"
|
|
|
|
|
class="test-table"
|
|
|
|
|
height="100%"
|
|
|
|
|
empty-text=" "
|
|
|
|
|
>
|
|
|
|
|
<template v-for="(item, index) in tableTitles" :key="index">
|
|
|
|
|
<el-table-column>
|
2023-01-30 17:54:24 +08:00
|
|
|
<template #default="scope" :column="item">
|
|
|
|
|
<span :test-id="`${item.prop}${scope.$index}`">{{scope.row[item.prop]}}</span>
|
2023-01-30 11:50:22 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table>
|
2022-12-06 17:01:46 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
/* vue-jest的测试示例 */
|
2023-01-13 17:42:25 +08:00
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
2023-01-10 10:09:13 +08:00
|
|
|
import axios from 'axios'
|
2023-01-13 17:42:25 +08:00
|
|
|
import { ref } from 'vue'
|
2023-01-17 17:56:44 +08:00
|
|
|
import indexedDBUtils from '@/indexedDB'
|
2022-12-06 17:01:46 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'Test',
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2023-01-10 10:09:13 +08:00
|
|
|
count: 0,
|
2023-01-17 17:56:44 +08:00
|
|
|
obj: { id: 1, title: 'title' },
|
2023-01-30 17:07:58 +08:00
|
|
|
differentParamData0: null,
|
|
|
|
|
differentParamData1: null,
|
2023-01-30 11:50:22 +08:00
|
|
|
indexedDBValue: null,
|
|
|
|
|
tableData: [
|
|
|
|
|
{
|
|
|
|
|
name: 'a',
|
|
|
|
|
age: 10
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'b',
|
|
|
|
|
age: 11
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
tableTitles: [
|
|
|
|
|
{ label: 'Name', prop: 'name' },
|
|
|
|
|
{ label: 'Age', prop: 'age' }
|
|
|
|
|
]
|
2022-12-06 17:01:46 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
click () {
|
|
|
|
|
this.count++
|
2023-01-10 10:09:13 +08:00
|
|
|
},
|
2023-01-11 15:50:04 +08:00
|
|
|
async getObj () {
|
|
|
|
|
axios.get('/api/getObjId').then(response => {
|
|
|
|
|
this.obj.id = response.data
|
|
|
|
|
})
|
|
|
|
|
axios.get('/api/getObjTitle').then(response => {
|
|
|
|
|
this.obj.title = response.data
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async getCount () {
|
|
|
|
|
axios.get('/api/getCount').then(response => {
|
|
|
|
|
this.count = response.data
|
2023-01-10 10:09:13 +08:00
|
|
|
})
|
2023-01-17 17:56:44 +08:00
|
|
|
},
|
2023-01-30 17:07:58 +08:00
|
|
|
async differentRequestParam () {
|
|
|
|
|
axios.get('/api/differentParam', { params: { name: 0 } }).then(response => {
|
|
|
|
|
this.differentParamData0 = response.data
|
|
|
|
|
})
|
|
|
|
|
axios.get('/api/differentParam', { params: { name: 1 } }).then(response => {
|
|
|
|
|
this.differentParamData1 = response.data
|
|
|
|
|
})
|
|
|
|
|
},
|
2023-01-17 17:56:44 +08:00
|
|
|
async setIndexedDBValue () {
|
|
|
|
|
await indexedDBUtils.selectTable('test').put({ id: 1, name: 'test' })
|
|
|
|
|
},
|
|
|
|
|
async getIndexedDBValue () {
|
|
|
|
|
this.indexedDBValue = await indexedDBUtils.selectTable('test').get(1)
|
2022-12-06 17:01:46 +08:00
|
|
|
}
|
|
|
|
|
},
|
2023-01-13 17:42:25 +08:00
|
|
|
setup () {
|
|
|
|
|
const { query } = useRoute()
|
|
|
|
|
const { currentRoute } = useRouter()
|
|
|
|
|
const localstorageValue = localStorage.getItem('key')
|
|
|
|
|
const lineTab = ref(query.lineTab || '')
|
|
|
|
|
const path = currentRoute.value.path
|
2022-12-06 17:01:46 +08:00
|
|
|
return {
|
2023-01-13 17:42:25 +08:00
|
|
|
lineTab,
|
|
|
|
|
path,
|
|
|
|
|
localstorageValue
|
2022-12-06 17:01:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|