mirror of
https://github.com/xiangshu233/vue3-vant4-mobile.git
synced 2025-04-25 11:06:55 +08:00
在写原子化 css 的时候通过 unocss 的 presetRemToPx 预设它可以原子化默认 rem 转换成 px,最后再由 postcss 把 px 转成 vw,从而让我们无痛使用原子化css closed #6, #20
70 lines
1.4 KiB
Vue
70 lines
1.4 KiB
Vue
<template>
|
|
<div>
|
|
<NavBar>
|
|
<template #right>
|
|
<span @click="handleNickname">保存</span>
|
|
</template>
|
|
</NavBar>
|
|
<van-form ref="formRef">
|
|
<van-field
|
|
v-model="formValue.sign"
|
|
class="mt-20px"
|
|
name="sign"
|
|
clearable
|
|
rows="4"
|
|
autosize
|
|
label="签名"
|
|
type="textarea"
|
|
maxlength="70"
|
|
placeholder="随知修行乃当务之急,然怠惰度日至今"
|
|
show-word-limit
|
|
/>
|
|
</van-form>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { onMounted, reactive, ref } from 'vue'
|
|
import type { FormInstance } from 'vant'
|
|
import { showToast } from 'vant'
|
|
import NavBar from './components/NavBar.vue'
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
|
const userStore = useUserStore()
|
|
|
|
const { sign } = userStore.getUserInfo
|
|
const formRef = ref<FormInstance>()
|
|
|
|
const formValue = reactive({
|
|
sign: '',
|
|
})
|
|
|
|
function handleNickname() {
|
|
formRef.value
|
|
?.validate()
|
|
.then(async () => {
|
|
try {
|
|
const formValue = formRef.value?.getValues()
|
|
showToast({
|
|
message: `当前表单值:${JSON.stringify(formValue)}`,
|
|
})
|
|
// do something
|
|
}
|
|
finally {
|
|
// after successful
|
|
}
|
|
})
|
|
.catch(() => {
|
|
console.error('验证失败')
|
|
})
|
|
}
|
|
|
|
onMounted(() => {
|
|
formValue.sign = sign ?? ''
|
|
})
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
|
|
</style>
|