DOM操作

2020-12-29 10:53 更新

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

操作獲取DOM元素

  1. <template>
  2. <view class='content'>
  3. <input id='num' type='number' autofocus/>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'api-test',
  9. apiready(){
  10. var num = $('#num').value;
  11. // var num = document.getElementById('num').value;
  12. console.log('input value: ' + num);
  13. }
  14. }
  15. </script>
  16. <style>
  17. .content{
  18. height: 100px;
  19. }
  20. </style>

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

  1. <template>
  2. <view class='content'>
  3. <list-view id='list' >
  4. <cell>
  5. <text>{item.title}</text>
  6. </cell>
  7. </list-view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'api-test',
  13. apiready(){
  14. var _data = ['一', '二', '三', '四'];
  15. var listview = $('#list');
  16. listview.load({
  17. data: _data
  18. });
  19. }
  20. }
  21. </script>
  22. <style>
  23. .content{
  24. height: 100px;
  25. }
  26. </style>

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

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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)