Giter Site home page Giter Site logo

simple-wxmp-vueify's Introduction

simple-wxmp-vueify

介绍

既有项目无法重构,但想在某些页面的JS中使用vue的语法?不想手动调用小程序内的setData()?这个库可能帮你解决一些问题

特性

  • 支持在代码中使用this.xxx表示data属性
  • 支持计算属性
  • 支持响应式更新视图,不用手动setData

使用Demo

$ git clone https://github.com/qk44077907/simple-wxmp-vueify.git

之后文件夹拷贝至项目根目录

//你的路径
import '/simple-wxmp-vueify/index.js'

Page({
    reactive: true,//在初始化页面时传入此字段,库将自动把页面转化为响应式
    data: {
        questionName: '',
        questionDesc: '',
        questionList: [
            {
                content: '',
            },
            {
                content: '',
            },
        ],
        questionTypeList: ['单选', '多选'],
        questionTypeIndex: 0,
    },
    computed: {
        questionType: function () {
            return this.questionTypeList[this.questionTypeIndex]
        }
    },
    addItem() {
        this.questionList.push({
            content: '',
        })
    },
    removeItem(e) {
        let index = e.target.dataset.index
        if (this.questionList.length <= 2) {
            return
        }
        this.questionList.splice(index, 1)
    }
});

wxml模板

<view class="question-panel">
    <view
            class="item"
            wx:for="{{questionList}}"
            wx:for-item="question"
            wx:for-index="index"
            wx:key="name"
    >
        <!--
        注意双向绑定更新需要在对应元素上指定data-path属性
        代表需要更新的属性相对data的路径,使用 '.'拼接
        如 'questionList.0.content'


        -->
        <textarea
                            bindinput="updateVM" data-path="questionList.{{index}}.content"
                            type="text" placeholder="{{'选项'+(index+1)}}"
                            placeholder-style="font-size:30rpx"
                            maxlength="40"
                            value="{{question.content}}"
                            auto-height
        >
        </textarea>
        <view
            class="icon"
            bindtap="removeItem"
            data-index="{{index}}"
        >
            删除
        </view>
        <view
            class="icon"
            bindtap="addItem"
            data-index="{{index}}"
        >
            添加
        </view>
    </view>
</view>

simple-wxmp-vueify's People

Stargazers

Zhazha_JiaYiZhen avatar Dainis Graveris avatar mr zhang avatar Dia avatar  avatar 热心市民黄先生 avatar guanglinmei avatar Kumiko Lau avatar D.Hu avatar  avatar Yitian Yang avatar  avatar Wenyun Pei avatar 轻茹莉莉酱 avatar  avatar Tina Sun avatar  avatar 厦漳泉 avatar Keo avatar 東方定助 avatar  avatar 静氣 avatar Erichen avatar  avatar Cynthia Xin avatar Nancy Raker avatar Joseph Wyatt avatar Sindre Sorhus avatar  avatar wym keith avatar porschebz avatar lyirs avatar Fanison Tomas avatar Farming Tong avatar  avatar  avatar 魔鬼·珺 avatar Nowwa avatar Yiyang123 avatar  avatar  avatar Eric Qian avatar  avatar baihe avatar Rocks Wang avatar

Watchers

James Cloos avatar Eric Qian avatar  avatar 魔鬼·珺 avatar Farming Tong avatar Keo avatar Nowwa avatar 轻茹莉莉酱 avatar 東方定助 avatar Wenyun Pei avatar Tina Sun avatar

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.