基于 Vue 插件将虚拟 DOM 渲染到 canvas
Rendering virtual DOM into canvas based on Vue plugin
mpvue vnode2canvas 使用文档请移步到这里文档
example url: demo
npm i vnode2canvas --saveFirst of all, you need to register vnode2Canvas
import Vue from 'vue'
import vnode2Canvas from 'vnode2Canvas'
Vue.use(vnode2Canvas)vnode2Canvas will render canvas by function renderCanvas option:
export default {
// define render options
canvasOptions: {
width: window.innerWidth, // canvas width
height: window.innerHeight // canvas height
},
renderCanvas (createElement) {
// ....
}
}after that vnode2Canvas will register a property named renderInstance on vue instance:
renderInstance = {
_ctx
_canvas
...
}A rolling list based on scroller to support lazy list loading.
…Support the following events:
clickmouseupmousedown // ...
renderCanvas(h) {
return h('view', {
on: {
click: (e, item) => {
alert('click Text')
}
}
},
'click event'
)
}
// ...If you think write CSS in JS is not comfortable, you can also load your external CSS file through a webpack loader.
// webpack
const canvasStyleLoader = require('canvas-style-loader')
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
// To avoid conflicts with CSS styles, you need to specify loading paths.
include: [
path.join(__dirname, './src')
],
use: {loader: 'canvasStyleLoader'}
}
]
}
};
// index.css
image {
left: 10px;
width: 100px;
height: 100px;
}
.title {
left: 120px;
width: 100px;
height: 100px;
fill: "#000";
font-size: 18px;
}
.desc {
left: 120px;
fill: '#999'
}
.date {
left: 120px;
fill: '#999'
}…暂无开放 Issues,或尚未同步最近议题。