- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的 Vue 组件中使用 CSS 掩码。我需要完成下面的toSvg
函数的实现。这会将来自 this.$slots.default
的 Vue VNode 呈现为 SVG 字符串。
<script>
export default {
computed: {
maskImage() {
const svg = this.toSvg(this.$slots.default);
const encodedSvg = btoa(svg);
return `url('data:image/svg+xml;base64,${encodedSvg}')`;
},
},
methods: {
toSvg(vnode) {
// TODO: How can I convert the VNode to a string like the one below?
// In React, I could use const svg = ReactDOMServer.renderToStaticMarkup(vnode);
return `<svg viewBox="0 0 260 68" xmlns="http://www.w3.org/2000/svg">
<rect x="80" y="32" width="160" height="12" rx="2" />
<rect width="180" height="20" rx="2" />
<rect x="80" y="52" width="95" height="12" rx="2" />
<rect y="26" width="68" height="42" rx="2" />
</svg>`;
},
},
render(createElement) {
return createElement("div", {
attrs: {
class: "skeleton",
style: `-webkit-mask-image: ${this.maskImage}; mask-image: ${this.maskImage};`,
},
});
},
};
</script>
<style lang="scss">
.skeleton {
animation: skeleton-animation 2s infinite linear;
background: linear-gradient(to right, hsl(30, 1, 99) 0%, hsl(30, 2, 95) 30%, hsl(30, 2, 95) 70%, hsl(30, 1, 99) 100%) 0 0 / 200% 100% hsl(30, 2, 95);
overflow: hidden;
position: relative;
width: 200px;
height: 100px;
@keyframes skeleton-animation {
100% {
background-position: -200% 0;
}
}
}
</style>
使用示例:
<u-skeleton>
<svg viewBox="0 0 260 68" xmlns="http://www.w3.org/2000/svg">
<rect x="80" y="32" width="160" height="12" rx="2" />
<rect width="180" height="20" rx="2" />
<rect x="80" y="52" width="95" height="12" rx="2" />
<rect y="26" width="68" height="42" rx="2" />
</svg>
</u-skeleton>
显示为:
最佳答案
使用Vue.extend
构造一个SVG组件constructor,在构造函数的render function
中,渲染slots.default
。
下一步是创建它的实例,然后 mount()
并获取编译后的 html。
Vue.component('v-test', {
computed: {
maskImage() {
let vnodes = this.$slots.default
let SVGConstructor = Vue.extend({
render: function (h, context) {
return h('svg', {
attrs: {
xmlns: 'http://www.w3.org/2000/svg'
}
}, vnodes)
}
})
let instance = new SVGConstructor()
instance.$mount()
const encodedSvg = btoa(instance.$el.outerHTML);
return `url('data:image/svg+xml;base64,${encodedSvg}')`;
}
},
render(createElement) {
return createElement("div", {
attrs: {
class: "skeleton",
style: `-webkit-mask-image: ${this.maskImage}; mask-image: ${this.maskImage};`,
},
})
},
})
new Vue({
el: '#app'
})
.skeleton {
animation: skeleton-animation 2s infinite linear;
background: linear-gradient(to right, #fcfcfc 0%, #f3f2f2 30%, #f3f2f2 70%, #fcfcfc 100%) 0 0 / 200% 100% #f3f2f2;
overflow: hidden;
position: relative;
width: 200px;
height: 100px;
}
@keyframes skeleton-animation {
100% {
background-position: -200% 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<v-test>
<svg viewBox="0 0 260 68" xmlns="http://www.w3.org/2000/svg">
<rect x="80" y="32" width="160" height="12" rx="2" />
<rect width="180" height="20" rx="2" />
<rect x="80" y="52" width="95" height="12" rx="2" />
<rect y="26" width="68" height="42" rx="2" />
</svg>
</v-test>
<hr>
<v-test>
<svg viewBox="0 0 260 68" x="0" y="0" xmlns="http://www.w3.org/2000/svg">
<rect x="80" y="32" width="160" height="12" rx="2" />
<rect width="180" height="20" rx="2" />
<rect x="80" y="52" width="95" height="12" rx="2" />
<rect y="26" width="68" height="42" rx="2" />
</svg>
<svg viewBox="0 0 260 68" x="20" y="-20" xmlns="http://www.w3.org/2000/svg">
<rect x="80" y="32" width="160" height="12" rx="2" />
<rect width="180" height="20" rx="2" />
<rect x="80" y="52" width="95" height="12" rx="2" />
<rect y="26" width="68" height="42" rx="2" />
</svg>
</v-test>
</div>
关于css - 如何将 Vue VNode 渲染为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64206148/
在 Mithril 中创建新组件时,vnode.attrs.value 和 vnode.state.value 有什么区别? 最佳答案 如 documentation 中所述: 状态 An objec
我在 6 节点集群上使用 DataStax Cassandra 1.2.3,每个集群都有四核 3GHz 处理器和 8GB RAM。最近开始用VNodes通过首先将 num_tokens 设置为 256
tl;博士: 给定一个 VueJS VNode对象,如何获取渲染后生成的 HTML 元素? 例如: > temp1 VNode {tag: "h1", data: undefined, childre
我正在尝试在我的 Vue 组件中使用 CSS 掩码。我需要完成下面的toSvg函数的实现。这会将来自 this.$slots.default 的 Vue VNode 呈现为 SVG 字符串。 exp
来自网址:http://www.datastax.com/dev/blog/virtual-nodes-in-cassandra-1-2 , 他们说: “如果相反,我们将随机化的 vnode 分布在整
回到这个问题: Why not enable virtual node in an Hadoop node? 我正在运行一个包含 2 个 cassandra 和 1 个分析节点的混合 3 节点集群,并
如何从其子组件的父组件渲染 vnode。我有一个渲染函数,它循环遍历在 this.$slots.default 中找到的子数组。目的是将 child 包裹在 li 标签中。 问题是子组件不呈现,我得到
我目前正在尝试创建一个组件来管理页面上的多个链接下拉列表和元素。此外,此元素提供了一个相当奇特的导航元素,其中包含自动滚动到此组件中所需元素的 anchor 链接。 问题是组件的实际内容完全是动态的,
在 NetBSD 系统文件 usr/src/sys/sys/vnode.h 中定义了一个 vnode 的结构。但是,我看到有时在执行操作时(比如说 ufs_getattr),一个 vnode* 作为
我们有每个节点一个 token 的 Cassandra 集群,总共 22 个节点,每个节点的平均负载为 500Gb。它具有用于主键空间的 SimpleStrategy 和 SimpleSnitch。
我对 Inode 与 Vnode 有一些疑问。据我了解,inode 是虚拟文件系统使用的文件的表示形式。而 vnodes 是特定于文件系统的。它是否正确? 另外,我很困惑 inode 是否是内核数据结
我想为 child 分配一些属性和类 VNode通过 data 目的。那只是有效。但是在我的 Vue.js 调查中,我没有看到使用这种模式,这就是为什么我认为修改 children 不是一个好主意 V
我是 Vue.js 世界的新手,我必须构建一个递归组件渲染器,将 JSON 转换为渲染的 Vue 组件。 到目前为止,递归渲染工作得很好,除了我传递给 createElement 函数的 props(
在 Unix 中 #include int close(int fd); close(fd) 还必须销毁与 fd 关联的文件表条目是否正确?是的,即使有另一个文件描述符引用同一个文件表条目? clo
在指令绑定(bind)方法中,有一个vnode.context.$watch,每次将该指令添加到 HTML 时,它还会添加另一个观察者和前一个观察者。因为同样的观察者不止一次地打电话。 有没有办法在调
我有一种情况,我有一个渲染函数将一些数据传递到一个作用域槽。作为此数据的一部分,我想包含一些由渲染函数构造的 VNode,这些 VNode 可以选择性地由作用域插槽使用。在模板中编写作用域槽以输出接收
我正在使用 kauth 系统来监控文件特定的更改。在我的 KAUTH_FILEOP_SCOPE 监听器中,当我收到任何通知时,我将其发送(排队)到用户进程。在用户进程中,当我尝试使用 访问文件创建日期
我是 C 初学者,正在学习 Graph 的一些数据结构。今天在维基百科上看了一段C代码: #define MAX_VERTEX_NUM 20 typedef struct ArcNod
在指令绑定(bind)上,我创建了一个事件“validate”的监听器以运行函数 updateMessage: vnode.context.$on('validate', () => { upd
我在 AWS 上的 Cassandra 1.2.11 (DSE) 上有一个 12 节点集群。我丢失了其中一个节点,因为它丢失了亚马逊上的临时驱动器(其中包含数据)。为了解决这个问题,我使用 nodet
我是一名优秀的程序员,十分优秀!