____  ___    _  _     _   _ _____     _______
 / ___|/ _ \  | || |   | | | |_ _\ \   / / ____|
| |  _| | | | | || |_  | |_| || | \ \ / /|  _|
| |_| | |_| | |__   _| |  _  || |  \ V / | |___
 \____|\___/     |_|   |_| |_|___|  \_/  |_____|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Vue中增加数组长度获得响应的问题

BY: @syt | CREATED: May 18, 2018, 4:36 a.m. | VOTES: 2 | PAYOUT: $0.00 | [ VOTE ]

[IMAGE: https://cn.vuejs.org/images/logo.png]

最近在学习Vue的过程中遇到一个问题,官方文档说由于 JavaScript 的限制,Vue 不能检测以下变动的数组:

> 当你修改数组的长度时,例如:vm.items.length = newLength

解决方法是使用

vm.items.splice(newLength)

但我在使用的时候却没有作用。这是我的代码:





{{ index }} : {{ item }}




    var app = new Vue({
      el: '#app',
      data: {
       items: ['a', 'b', 'c']
      }
    })
  </script

页面运行后,我在chrome的console中输入

app.items.splice(10)

页面没变化,重试几次都没效果,我猜测官方说的解决方法有问题,于是发了issue进行询问。最后得知:

splice() 增加数组的长度必须提供值(可为空,即使用 app.items.splice(3,0,'','','','g','h') 的形式),而减少数组长度则没有这个限制

TAGS: [ #cn ] [ #vuejs ] [ #web ] [ #develop ]

Replies

@steemitboard | Aug. 31, 2018, 5:02 a.m. | Votes: 0 | [ VOTE ]

Congratulations @syt! You have received a personal award!

[IMAGE: https://steemitimages.com/70x70/http://steemitboard.com/@syt/birthday1.png] 1 Year on Steemit
Click on the badge to view your Board of Honor.

> Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

@steemitboard | Aug. 31, 2019, 5:03 a.m. | Votes: 0 | [ VOTE ]

Congratulations @syt! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@syt/birthday2.pngHappy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>