Skip to content

Commit

Permalink
docs: Add sections of "watch() API" and "Template Refs"
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Aug 22, 2019
1 parent 85001f2 commit 58b1d45
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 2 deletions.
100 changes: 99 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Component = {

# Limitations

## Unwrap
## `Ref` Unwrap

`Unwrap` is not working with Array index.

Expand Down Expand Up @@ -136,3 +136,101 @@ b.list.push(
// unwrapped
b.list[1].count === 1; // true
```
---
## `watch()` API
`onTrack` and `onTrigger` are not available in `WatchOptions`.
---
## Template Refs
> ✅ Support     ❌ Not Support
✅ String ref && return it from `setup()`:
```html
<template>
<div ref="root"></div>
</template>

<script>
export default {
setup() {
const root = ref(null);

onMounted(() => {
// the DOM element will be assigned to the ref after initial render
console.log(root.value); // <div/>
});

return {
root,
};
},
};
</script>
```
✅ String ref && return it from `setup()` && Render Function / JSX:
```jsx
export default {
setup() {
const root = ref(null);

onMounted(() => {
// the DOM element will be assigned to the ref after initial render
console.log(root.value); // <div/>
});

return {
root,
};
},
render() {
// with JSX
return () => <div ref="root" />;
},
};
```
❌ Function ref:
```html
<template>
<div :ref="el => root = el"></div>
</template>

<script>
export default {
setup() {
const root = ref(null);

return {
root,
};
},
};
</script>
```
❌ Render Function / JSX:
```jsx
export default {
setup() {
const root = ref(null);

return () =>
h('div', {
ref: root,
});

// with JSX
return () => <div ref={root} />;
},
};
```
100 changes: 99 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Component = {

# 限制

## Unwrap
## `Ref` Unwrap

数组索引属性无法进行自动的`Unwrap`:

Expand Down Expand Up @@ -136,3 +136,101 @@ b.list.push(
// unwrapped
b.list[1].count === 1; // true
```
---
## `watch()` API
不支持 `onTrack``onTrigger` 选项.
---
## Template Refs
> ✅ Support &nbsp;&nbsp;&nbsp;&nbsp;❌ Not Support
✅ String ref && return it from `setup()`:
```html
<template>
<div ref="root"></div>
</template>

<script>
export default {
setup() {
const root = ref(null);

onMounted(() => {
// the DOM element will be assigned to the ref after initial render
console.log(root.value); // <div/>
});

return {
root,
};
},
};
</script>
```
✅ String ref && return it from `setup()` && Render Function / JSX:
```jsx
export default {
setup() {
const root = ref(null);

onMounted(() => {
// the DOM element will be assigned to the ref after initial render
console.log(root.value); // <div/>
});

return {
root,
};
},
render() {
// with JSX
return () => <div ref="root" />;
},
};
```
❌ Function ref:
```html
<template>
<div :ref="el => root = el"></div>
</template>

<script>
export default {
setup() {
const root = ref(null);

return {
root,
};
},
};
</script>
```
❌ Render Function / JSX:
```jsx
export default {
setup() {
const root = ref(null);

return () =>
h('div', {
ref: root,
});

// with JSX
return () => <div ref={root} />;
},
};
```

0 comments on commit 58b1d45

Please sign in to comment.