Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vnode2canvas

> 编程语言
Open source

Rendering virtual DOM into canvas based on Vue plugin

385 stars0 likes1 views
WebsiteGitHub

About

Rendering virtual DOM into canvas based on Vue plugin

vnode2canvas

Rendering virtual DOM into canvas based on Vue plugin

mpvue vnode2canvas 使用文档请移步到这里文档

example

example url: demo

usage

install

bash
npm i vnode2canvas --save

use in Vue

First of all, you need to register vnode2Canvas

javascript
import Vue from 'vue'
import vnode2Canvas from 'vnode2Canvas'

Vue.use(vnode2Canvas)

vnode2Canvas will render canvas by function renderCanvas option:

javascript
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:

javascript
renderInstance = {
  _ctx
  _canvas
  ...
}

1. render scroll list

A rolling list based on scroller to support lazy list loading.

usage:
…

2. events

Support the following events:

  1. click
  2. mouseup
  3. mousedown
  4. to be continue...
usage
  // ...
  renderCanvas(h) {
    return h('view', {
        on: {
          click: (e, item) => {
            alert('click Text')
          }
        }
      },
      'click event'
    )
  }
  // ...

3. use css file for webpack loader

If you think write CSS in JS is not comfortable, you can also load your external CSS file through a webpack loader.

canvas-style-loader

javascript
// 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'}
      }
    ]
  }
};
css
// 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· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言