npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-template-render

v1.0.8

Published

将vue的template语法字符串渲染为dom,返回dom,可获得html Render the vue template syntax string as dom, return dom, and get html

Downloads

19

Readme

vue-template-render

说明

将vue的template语法字符串渲染为dom,返回dom,可获得html

introduce

Render the vue template syntax string as dom, return dom, and get html

npm 安装

npm install vue-template-render

快速上手

//# es6导入
// import TemplateRender from 'vue-template-render'
//# cmd导入
const TemplateRender = require('vue-template-render')

//no options
const vueTemplate1 = `
    <div><span v-for="i in 10">{{ i }}</span></div>
    `
//# 输出 dom
console.log(TemplateRender.render(vueTemplate1))
//# 输出 html
console.log(TemplateRender.render(vueTemplate1).outerHTML)

//options
const vueTemplate2 = `
    <div><span v-for="i in 10">{{msg}} --- {{ i }}</span></div>
    `

//# 输出 dom
console.log(TemplateRender.render(vueTemplate2, {data: {msg: 'hello'}}))
//# 输出 html
console.log(TemplateRender.render(vueTemplate2, {data: {msg: 'hello'}}).outerHTML)

输出内容

<div>
    <span>1</span>
    <span>2</span>
    <span>3</span>
    <span>4</span>
    <span>5</span>
    <span>6</span>
    <span>7</span>
    <span>8</span>
    <span>9</span>
    <span>10</span>
</div>
<div>
    <span>hello --- 1</span>
    <span>hello --- 2</span>
    <span>hello --- 3</span>
    <span>hello --- 4</span>
    <span>hello --- 5</span>
    <span>hello --- 6</span>
    <span>hello --- 7</span>
    <span>hello --- 8</span>
    <span>hello --- 9</span>
    <span>hello --- 10</span>
</div>

内部实现

import Vue from 'vue'
import {ComponentOptions} from "vue/types/options";

export default class TemplateRender {
    static render<V extends Vue = Vue>(template: string = '', options?: ComponentOptions<V>): Element {
        const htmlVue = new Vue({
            el: document.createElement('div'),
            ...options,
            template: template
        })
        return htmlVue.$el
    }

    static renderOptions<V extends Vue = Vue>(options: ComponentOptions<V>): Element {
        const htmlVue = new Vue({
            el: document.createElement('div'),
            ...options,
        })
        return htmlVue.$el
    }
}