Skip to content

Commit a47985f

Browse files
committed
docs: add notes
1 parent d82a1a1 commit a47985f

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Now with `lit-html` you can use `.js` and `.ts` extensions:
5656
```js
5757
import { html } from 'lit-vue'
5858

59-
const template = html`
59+
html`
6060
<div>
6161
<h1>hello</h1>
6262
<hr />
@@ -71,9 +71,6 @@ const template = html`
7171
`
7272

7373
export default {
74-
// `template` is not necessary here, just to make linter happy
75-
// Actually its value is always `undefined`
76-
template,
7774
data() {
7875
return {
7976
count: 0
@@ -87,6 +84,51 @@ export default {
8784
}
8885
```
8986

87+
<details><summary>You might need to configure the ESLint rule: no-unused-expressions</summary><br>
88+
89+
ESLint might complain about the the <code>html&#x60;&#x60;</code> expression not being used when you enabled the rule: [no-unused-expressions](http://eslint.cn/docs/rules/no-unused-expressions), there're three ways to solve it:
90+
91+
1. Disable this rule for tagged template expression in your ESLint config
92+
93+
```json
94+
{
95+
"rules": {
96+
"no-unused-expressions": ["error", { "allowTaggedTemplates": true }]
97+
}
98+
}
99+
```
100+
101+
2. Or export it
102+
103+
```js
104+
export const template = html`
105+
<div>{{ count }}</div>
106+
`
107+
```
108+
109+
You can just assign it to a variable and export it, though the exported variable will never be used. The return value of `html` tag is always undefined.
110+
111+
3. Or use it as component option
112+
113+
```js
114+
const template = html`
115+
<div>{{ count }}</div>
116+
`
117+
118+
export default {
119+
template,
120+
data() {
121+
return {
122+
count: 0
123+
}
124+
}
125+
}
126+
```
127+
128+
Similar to #2, this may look more natural because `template` is a legit Vue component option.
129+
130+
</details>
131+
90132
## How to use
91133

92134
### Use with webpack

0 commit comments

Comments
 (0)