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

kgm-template

v1.0.2

Published

这是一个响应式前端模板引擎

Downloads

14

Readme

数据响应式前端模板引擎

kgm-template 是一个数据响应式的前端 (Javascript) 模板引擎,使用 NT 可以使你的代码实现数据和视图模型的分离(MVC)。

码云地址

https://gitee.com/kgm0515/kgm-template

标签的方式引入

<script type="text/javascript" src="kgm-template.min.js></script>

ES6中使用

安装插件: npm i kgm-template

使用方式1: 数据响应式,自动渲染

创建实例,传入模板、数据、方法等,方法可以调用修改data中的数据,页面随着data修改实时刷新

import Template from 'kgm-template'
// 自动解析处理和缓存模板,绑定数据和函数
new Template({ 
  regConfig = null,      // 正则配置
  namespace = 'default', // 命名空间
  template = '',          // 模板
  rootId = '',             // 父元素id
  rootDom = null,         // 元素节点
  data= {},               // 绑定的数据
  methods ={},            // 方法
  components = {},        // 内部组件实例
})

使用方式2: 仅编译,需要手动渲染

仅编译模版暂不渲染,它会返回一个html节点字符串.

import Template from 'kgm-template'

const instance = Template.getInstance({})
let html = instance.compile(tpl, data);
// 渲染
document.getElementById('app').innerHTML = HTML

自定义模板语法边界符

变量正则: /{{([\s\S]+?)}}/g

<!-- 绑定变量 -->
<h3>{{info.name}}\</h3>

<!-- 三元表达式 -->
<h3>{{info.age >  ? "已成年": "未成年"}}\</h3>
<button>{{ !content[i].edit ? "编辑": "保存" }}</button>

js表达式正则: /<%([\s\S]+?)%>/g

<!-- 判断 -->
<% if(descript){ %> 
   <div>{{descript}}</div> 
<% }else{ %> 
     <div> 暂无描述</div> 
<% } %>

<!-- 循环 -->
<%  for(let i = 0; i<content.length; i++){ %>
  <li>
    <% if(content[i].edit){ %>
      <b>{{content[i].text}}</b> 
    <% }else{ %>
      <b>{{content[i].text}}</b> 
    <% } %>
  </li>
<% } %>

注释正则:/<!--([\s\S]+?)-->/g

<!-- 注释节点 -->

绑定方法:@事件名: @事件名="

<!-- 绑定点击事件 -->
<button @click="deleteItem(event, {{i}})">保存</button>

<!-- 绑定输入事件 -->
<input value="{{content[i].text}}" @input="modifyContent(this, ///'{{item}}///'" />