mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-12-13 00:48:58 +08:00
style: format
This commit is contained in:
@@ -88,7 +88,7 @@ Default: `false`
|
||||
函数式组件
|
||||
|
||||
```jsx
|
||||
const App = () => <div></div>;
|
||||
const App = () => <div></div>
|
||||
```
|
||||
|
||||
在 render 中使用
|
||||
@@ -96,27 +96,25 @@ const App = () => <div></div>;
|
||||
```jsx
|
||||
const App = {
|
||||
render() {
|
||||
return <div>Vue 3.0</div>;
|
||||
return <div>Vue 3.0</div>
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
import { withModifiers, defineComponent } from 'vue';
|
||||
import { withModifiers, defineComponent } from 'vue'
|
||||
|
||||
const App = defineComponent({
|
||||
setup() {
|
||||
const count = ref(0);
|
||||
const count = ref(0)
|
||||
|
||||
const inc = () => {
|
||||
count.value++;
|
||||
};
|
||||
count.value++
|
||||
}
|
||||
|
||||
return () => (
|
||||
<div onClick={withModifiers(inc, ['self'])}>{count.value}</div>
|
||||
);
|
||||
return () => <div onClick={withModifiers(inc, ['self'])}>{count.value}</div>
|
||||
},
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
Fragment
|
||||
@@ -127,20 +125,20 @@ const App = () => (
|
||||
<span>I'm</span>
|
||||
<span>Fragment</span>
|
||||
</>
|
||||
);
|
||||
)
|
||||
```
|
||||
|
||||
### Attributes / Props
|
||||
|
||||
```jsx
|
||||
const App = () => <input type="email" />;
|
||||
const App = () => <input type="email" />
|
||||
```
|
||||
|
||||
动态绑定:
|
||||
|
||||
```jsx
|
||||
const placeholderText = 'email';
|
||||
const App = () => <input type="email" placeholder={placeholderText} />;
|
||||
const placeholderText = 'email'
|
||||
const App = () => <input type="email" placeholder={placeholderText} />
|
||||
```
|
||||
|
||||
### 指令
|
||||
@@ -150,12 +148,12 @@ const App = () => <input type="email" placeholder={placeholderText} />;
|
||||
```jsx
|
||||
const App = {
|
||||
data() {
|
||||
return { visible: true };
|
||||
return { visible: true }
|
||||
},
|
||||
render() {
|
||||
return <input v-show={this.visible} />;
|
||||
return <input v-show={this.visible} />
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
#### v-model
|
||||
@@ -191,7 +189,7 @@ h(A, {
|
||||
modifier: true,
|
||||
},
|
||||
'onUpdate:argument': ($event) => (val = $event),
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
#### v-models (从 1.1.0 开始不推荐使用)
|
||||
@@ -234,7 +232,7 @@ h(A, {
|
||||
modifier: true,
|
||||
},
|
||||
'onUpdate:bar': ($event) => (bar = $event),
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
#### 自定义指令
|
||||
@@ -245,18 +243,18 @@ h(A, {
|
||||
const App = {
|
||||
directives: { custom: customDirective },
|
||||
setup() {
|
||||
return () => <a v-custom:arg={val} />;
|
||||
return () => <a v-custom:arg={val} />
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
const App = {
|
||||
directives: { custom: customDirective },
|
||||
setup() {
|
||||
return () => <a v-custom={[val, 'arg', ['a', 'b']]} />;
|
||||
return () => <a v-custom={[val, 'arg', ['a', 'b']]} />
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 插槽
|
||||
@@ -269,20 +267,20 @@ const A = (props, { slots }) => (
|
||||
<h1>{slots.default ? slots.default() : 'foo'}</h1>
|
||||
<h2>{slots.bar?.()}</h2>
|
||||
</>
|
||||
);
|
||||
)
|
||||
|
||||
const App = {
|
||||
setup() {
|
||||
const slots = {
|
||||
bar: () => <span>B</span>,
|
||||
};
|
||||
}
|
||||
return () => (
|
||||
<A v-slots={slots}>
|
||||
<div>A</div>
|
||||
</A>
|
||||
);
|
||||
)
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// or
|
||||
|
||||
@@ -291,10 +289,10 @@ const App = {
|
||||
const slots = {
|
||||
default: () => <div>A</div>,
|
||||
bar: () => <span>B</span>,
|
||||
};
|
||||
return () => <A v-slots={slots} />;
|
||||
}
|
||||
return () => <A v-slots={slots} />
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// 或者,当 `enableObjectSlots` 不是 `false` 时,您可以使用对象插槽
|
||||
const App = {
|
||||
@@ -309,9 +307,9 @@ const App = {
|
||||
</A>
|
||||
<B>{() => 'foo'}</B>
|
||||
</>
|
||||
);
|
||||
)
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### 在 TypeScript 中使用
|
||||
|
||||
Reference in New Issue
Block a user