Git Product home page Git Product logo

minx's Introduction

Minx

Minx是一个简单的MVVM框架.

功能

  • {{ xxx }}
  • x-html
  • x-model
  • x-if
  • x-for
  • :/x-attr:[attr]
  • x-on:[event]

插值

文本

<h3> {{ title }} </h3>

表达式

{{ age + 1 }}
{{ age ? 'YES' : 'NO' }}
{{ fns['method']('hello') }}

指令

x-model:双向绑定

<input x-model="message">

x-for: 列表

<li x-for="todo:list">
    <div>{{ todo.creator }}</div>
</li>

或者使用索引

<li x-for="(todo:index):list">
    <div>{{ todo.creator }}</div>
</li>

x-attr:[attr]: 为节点添加属性

可以使用字符串进行拼接

<ul :id="title">
<div><a x-attr:href="url">{{ user }}的BLOG</a></div>
<div x-attr:class="user"></div>
<p x-attr:href="url+'/'+todo.id"></p>

x-on:[event]:绑定事件

可以使用参数,实际参数使用数组传入,按照索引使用参数

<button x-on:click="click('Hello')">CLICK TO SAY: Hello</button>

x-if: 是否渲染该节点

<div x-if="value">是否显示</div>

Router.hash

// 获取hash值
let _hash = Router.hash.value;

// 设置hash值
Router.hash.value = { scope: 0, page: 2 }; // url#!/scope=0&page=2

// 获取hash参数值
Router.hash.get('scope'); // 0
Router.hash.get('page');  // 2

// 设置参数值
Router.hash.set('scope', 2); // url#!/scope=2&page=2
Router.hash.set('page', 5);  // url#!/scope=2&page=5

// 绑定事件
Router.hash.change(()=>{alter('change!')});

minx's People

Contributors

ffiirree avatar

Stargazers

 avatar

Watchers

 avatar

minx's Issues

列表编译Watcher绑定数据错误

绑定错误

编译列表时,将列表作为子节点单独编译

        _data.value.forEach(item =>{
            const _clone = node.cloneNode(true);

            let item_data = {};
            item_data[_itemDataName] = item;
            item_data.__proto__ = this.$vm;
            let _c = new Compile(_clone, item_data);

            parent.appendChild(_clone);
        });

这样,编译过程中,Watcher会绑定到子数据item_data上,而不是父亲的数据上,导致视图无法更新。

数组绑定

数组绑定

数据绑定部分可以劫持普通对象,还不能对数组进行劫持。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.