Skip to content

Commit

Permalink
@Style scoped update
Browse files Browse the repository at this point in the history
  • Loading branch information
joon610 committed Aug 21, 2019
1 parent 819a1b5 commit 9332c9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Vue Corator


## Update
- [x] @style: changed global to scoped 2019/08/22


## License

MIT License
Expand Down Expand Up @@ -84,23 +88,8 @@ See also: [Runtime + Compiler vs. Runtime only.](https://vuejs.org/v2/guide/inst
<template>
<div>
<styleTagName1>
.title { background:red }
.title { background:red } // .title [data-v-<hash>] {background:red}
</styleTagName1>
<styleTagName2>
@import "./assets/test.css"
</styleTagName2>
</div>
</template>
```
or

```html
<template>
<div>
<styleTagName1>
</styleTagName1>
<styleTagName2>
</styleTagName2>
</div>
</template>
```
Expand All @@ -116,11 +105,6 @@ export default class YourComponent extends Vue {
.title { background:pink }
`;
}
@Style()
private styleTagName2() {
return '@import "./assets/test.css"';
}

}
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-corator",
"version": "1.6.1",
"version": "1.6.2",
"description": "this is TypeScript Vue decorator.",
"main": "lib/vue-corator.d.ts",
"module": "lib/vue-corator.js",
Expand Down
30 changes: 16 additions & 14 deletions src/vue-corator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ export function Super(component: any) {

export function Style() {
return (target: Vue, key: string, descriptor: PropertyDescriptor) => {
const style = descriptor.value();
const style = descriptor.value();
createDecorator((options, k) => {
const newComponent = {
// @ts-ignore
render(createElement: any) {
return createElement('style',
{ attrs: { type: 'text/css', lang: 'css' } },
// @ts-ignore
[this.$slots.default || style]);
}
// @ts-ignore
render(createElement: any) {
// @ts-ignore
const styleScoped = style.replace(/{./gi, '[' + options._scopeId + '] {');
return createElement('style',
{ attrs: { type: 'text/css', lang: 'css'} },
// @ts-ignore
[this.$slots.default || styleScoped ]);
}
};
createDecorator((options, k) => {
options.components = options.components || {};
options.components[key] = newComponent;
})(target, key);
};
}
options.components = options.components || {};
options.components[key] = newComponent;
})(target, key);
};
}

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

0 comments on commit 9332c9a

Please sign in to comment.