New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

wx-computed2

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wx-computed2

几乎照搬vue源码为小程序增加computed和watch特性

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

wx-computed

几乎照搬vue源码为小程序增加computed和watch特性

使用

这里配合wx-wrapper来进行演示,推荐使用这种方式进行全局引入

import wrapper from 'wx-wrapper';
import computed from 'wx-computed2';

// 一次性为所有页面和组件引入该功能
wrapper({
    Page: {
        onLoad() {
            computed(this);
        }
    },
    Component: {
        attached(rawObj) {
            // 由于小程序限制, 自定义属性需手动绑定
            ['computed', 'watch'].forEach(v => this[v] = rawObj[v]);
            computed(this);
        }
    }
});

// 当然也可直接在Page或Component中单独手动引入
Page({
    data: {num: 1},
    computed: {
        num2() {
            return this.data.num << 1;
        }
    },
    watch: {
        num2() {
            console.log('watch num2');
        }
    },
    onLoad() {
        // 不推荐这样引入,太麻烦
        computed(this);
    }

});

Keywords

wx

FAQs

Package last updated on 29 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts