DOM操作

2020-12-29 10:53 更新

avm.js在提供數(shù)據(jù)綁定和狀態(tài)管理驅(qū)動(dòng)界面更新的基礎(chǔ)上,同時(shí)支持document以及類似jquery方式使用$函數(shù)獲取和操作真實(shí)DOM。

操作獲取DOM元素

<template>  
    <view class='content'>
        <input id='num' type='number' autofocus/>
    </view>  
</template>  
<script>
    export default {  
        name: 'api-test',
        apiready(){
            var num = $('#num').value;
            // var num = document.getElementById('num').value;
            console.log('input value: ' + num);
        }
    }
</script>
<style>
    .content{
        height: 100px;
    }
</style>

獲取DOM元素并調(diào)用組件API

<template>  
    <view class='content'>
        <list-view id='list' >
            <cell>
                <text>{item.title}</text>
            </cell>
        </list-view>
    </view>  
</template>  
<script>
    export default {  
        name: 'api-test',
        apiready(){
            var _data = ['一', '二', '三', '四'];
            var listview = $('#list');
            listview.load({
                data: _data
            });
        }
    }
</script>
<style>
    .content{
        height: 100px;
    }
</style>

其中,listview.load接口請(qǐng)參考list-view組件api文檔。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)