doc: update vue.md #125

This commit is contained in:
jaywcjlove 2022-11-18 12:39:34 +08:00
parent 84a545cbf6
commit 37d647eb67

View File

@ -224,8 +224,9 @@ data() {
``` ```
### 获取事件对象 ### 获取事件对象
<!--rehype:wrap-class=row-span-2-->
```js ```html
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
@ -240,8 +241,9 @@ const onClick = function(e){
``` ```
### 传参的同时获取事件对象 ### 传参的同时获取事件对象
<!--rehype:wrap-class=row-span-2-->
```js ```html
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
@ -251,9 +253,12 @@ const onClick = function(msg, e){
</script> </script>
<template> <template>
<button @click="onClick('Hello Vue!', $event)">click</button> <button @click="onClick('Hello Vue!', $event)">
click
</button>
</template> </template>
``` ```
<!--rehype:className=wrap-text-->
### 动态参数 ### 动态参数
@ -301,8 +306,9 @@ v-on:submit.prevent="onSubmit"
``` ```
### 自定义指令 Directives ### 自定义指令 Directives
<!--rehype:wrap-class=row-span-2-->
```js ```html
<script setup> <script setup>
const vAdmin = { const vAdmin = {
created(el, binding, vnode, prevVnode) { created(el, binding, vnode, prevVnode) {
@ -315,8 +321,9 @@ const vAdmin = {
<button v-admin>Settings</button> <button v-admin>Settings</button>
</template> </template>
``` ```
<!--rehype:className=wrap-text-->
更多指令函数参考:<https://vuejs.org/guide/reusability/custom-directives.html> 更多[指令函数参考](https://vuejs.org/guide/reusability/custom-directives.html)
响应式基础 响应式基础
--- ---
@ -380,7 +387,6 @@ export default defineComponent({
```html {1} ```html {1}
<script setup> <script setup>
// setup语法糖用于简化代码尤其是当需要暴露的状态和方法越来越多时
import { reactive } from 'vue'; import { reactive } from 'vue';
const state = reactive({ count: 0 }) const state = reactive({ count: 0 })
@ -397,6 +403,8 @@ function increment() {
</template> </template>
``` ```
**`setup`** 语法糖用于简化代码,尤其是当需要暴露的状态和方法越来越多时
### 用 `ref()` 定义响应式变量 ### 用 `ref()` 定义响应式变量
```js ```js