Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define CSS variables directly via component option #6

Open
egoist opened this issue Jan 18, 2019 · 2 comments
Open

Define CSS variables directly via component option #6

egoist opened this issue Jan 18, 2019 · 2 comments

Comments

@egoist
Copy link
Owner

egoist commented Jan 18, 2019

<template>
  <h1>hello</h1>
</template>

<script>
export default {
  cssVariables() {
	return {
	  fontSize: this.size + 'px'
	}
  }
}
</script>

<style scoped>
h1 {
  font-size: var(--fontSize);
}
</style>
@danielwaltz
Copy link

Doesn't feels quite as elegant to me, but it definitely helps when you need to be explicit about the units you're using. I have no idea what the overhead might be, but I think having a css var available for every data item/prop would be nicer than having to be explicit about what is available to the style block. I think data/props with a number type could probably default to px as well (unless it's 0).

@brandonpittman
Copy link

This feels Vue-like. You have to tell the templates what components are available, so why not tell style blocks which variables are available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants