Skip to content

Commit 9332c9a

Browse files
committed
@Style scoped update
1 parent 819a1b5 commit 9332c9a

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Vue Corator
22

33

4+
## Update
5+
- [x] @style: changed global to scoped 2019/08/22
6+
7+
48
## License
59

610
MIT License
@@ -84,23 +88,8 @@ See also: [Runtime + Compiler vs. Runtime only.](https://vuejs.org/v2/guide/inst
8488
<template>
8589
<div>
8690
<styleTagName1>
87-
.title { background:red }
91+
.title { background:red } // .title [data-v-<hash>] {background:red}
8892
</styleTagName1>
89-
<styleTagName2>
90-
@import "./assets/test.css"
91-
</styleTagName2>
92-
</div>
93-
</template>
94-
```
95-
or
96-
97-
```html
98-
<template>
99-
<div>
100-
<styleTagName1>
101-
</styleTagName1>
102-
<styleTagName2>
103-
</styleTagName2>
10493
</div>
10594
</template>
10695
```
@@ -116,11 +105,6 @@ export default class YourComponent extends Vue {
116105
.title { background:pink }
117106
`;
118107
}
119-
@Style()
120-
private styleTagName2() {
121-
return '@import "./assets/test.css"';
122-
}
123-
124108
}
125109
```
126110

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-corator",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "this is TypeScript Vue decorator.",
55
"main": "lib/vue-corator.d.ts",
66
"module": "lib/vue-corator.js",

src/vue-corator.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ export function Super(component: any) {
1515

1616
export function Style() {
1717
return (target: Vue, key: string, descriptor: PropertyDescriptor) => {
18-
const style = descriptor.value();
18+
const style = descriptor.value();
19+
createDecorator((options, k) => {
1920
const newComponent = {
20-
// @ts-ignore
21-
render(createElement: any) {
22-
return createElement('style',
23-
{ attrs: { type: 'text/css', lang: 'css' } },
24-
// @ts-ignore
25-
[this.$slots.default || style]);
26-
}
21+
// @ts-ignore
22+
render(createElement: any) {
23+
// @ts-ignore
24+
const styleScoped = style.replace(/{./gi, '[' + options._scopeId + '] {');
25+
return createElement('style',
26+
{ attrs: { type: 'text/css', lang: 'css'} },
27+
// @ts-ignore
28+
[this.$slots.default || styleScoped ]);
29+
}
2730
};
28-
createDecorator((options, k) => {
29-
options.components = options.components || {};
30-
options.components[key] = newComponent;
31-
})(target, key);
32-
};
33-
}
31+
options.components = options.components || {};
32+
options.components[key] = newComponent;
33+
})(target, key);
34+
};
35+
}
3436

3537
export function NextTick() {
3638
return (target: Vue, key: string, descriptor: any) => {

0 commit comments

Comments
 (0)