【发布时间】:2019-01-26 16:56:55
【问题描述】:
我正在做一个应用程序,我需要在 Vue JS 的单个文件组件中提取样式标记内的 CSS。
所以我有这个基本模板:
<template>
<div class="wrapper">
<button class="wrapper__button" @click="sendRequest()" click me></button>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
methods: {
sendRequest () {
console.log(document.getElementsByTagName("STYLE")[0].innerHTML)
this.$http.post('http://localhost:3000/users/pdf', 'random string').then((response) => {
console.log(response.data)
})
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.wrapper__button {
background-color: yellow;
}
</style>
有没有一种方法可以用 Javascript 获取 vue 组件中样式内的所有数据?
谢谢各位
【问题讨论】:
-
您的意思是要在变量中获取的 css 样式吗?或者您想从组件中设置 html 样式
-
我想得到 里面的所有css
-
我很好奇为什么需要提取
style标签?编译后的(如果使用scoped会加上[data...]),还是哪个版本??我不相信这是可能的,甚至是不希望的。 -
@Xan 如果我的回答解决了你的赏金问题,请手动奖励赏金,因为原作者最后一次出现在 11 个月前...
标签: javascript css vue.js sass vue-loader