You should not mix ‘v-for‘ with ‘v-if‘

编写下面的代码:

<el-table-column
  v-for="(th, key) in tableHeader"
  v-if="!checkNotAnyAuth(th)"
  :key="key"
  :prop="th.prop"
  :label="th.label"
  :fixed="th.fixed"
  :min-width="th.minWidth"
  :width="th.width"
  align="center"
  element-loading-text="拼命加载中"
>

在编写代码保存,运行之后报错:
The 'tableHeader' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'

如图:
在这里插入图片描述
中文意思是:'v-for’指令中的’tableHeader’变量应该被替换为一个计算属性,返回过滤后的数组。你不应该把v-for和v-if混在一起

我们可理解为:

在进行项目开发的时候因为在一个标签上同时使用了v-for和v-if两个指令导致的报错。

原因:v-for的优先级会高于v-if,因此v-if会重复运行在每个v-for中
弊端:这样重复的运算会消耗计算机性能,降低浏览器加载速度,在开发过程中应该尽量避浏览器开不必要性能的消耗

我们可以这样写:使用template标签进行包裹(template为html5的新标签,无特殊含义)

<template v-for="(th, key) in tableHeader">
  <el-table-column
	  v-if="!checkNotAnyAuth(th)"
	  :key="key"
	  :prop="th.prop"
	  :label="th.label"
	  :fixed="th.fixed"
	  :min-width="th.minWidth"
	  :width="th.width"
	  align="center"
	  element-loading-text="拼命加载中"
	> 
	</el-table-column>    
</template>

注意:key值写el-table-column标签里面

这样就解决了v-for和v-if使用时报错和损耗性能问题。
最后,欢迎各位小伙伴留言,或者点个关注,以后我会不定期更新我的技术博客。同时,在遇到问题时候可以私信我,我们大家一起解决!

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
webim-for-dotnet4开发说明: ==================== webim plugin for dotnet mvc3 Demo ==== Import 'WebimPlugin' Project to Visual Web Developer 2010. (Notice: MVC3 Required) Build and Run Developer Guide =============== Create Database --------------- import install.sql if your database is MySQL Coding WebimPlugin.cs ----------------------- implements these methods: ```dotnet public WebimEndpoint Endpoint(); public IEnumerable<WebimEndpoint> Buddies(string uid); public IEnumerable<WebimEndpoint> BuddiesByIds(string uid, string[] ids); public WebimRoom findRoom(string roomId); public IEnumerable<WebimRoom> Rooms(String uid); public IEnumerable<WebimRoom> RoomsByIds(String uid, String[] ids); public IEnumerable<WebimMember> Members(string roomId); public IEnumerable<WebimNotification> Notifications(string uid); public IEnumerable<WebimMenu> Menu(string uid); ``` Coding WebimModel.cs ----------------------- implements these methods to access database: ```dotnet public IEnumerable<WebimHistory> Histories(string uid, string with, string type = "chat", int limit = 50); public IEnumerable<WebimHistory> OfflineHistories(string uid, int limit = 50); public void InsertHistory(string uid, WebimMessage msg); public void ClearHistories(string uid, string with); public void OfflineHistoriesReaded(string uid); public string GetSetting(string uid); public void SaveSetting(string uid, string data); ``` Coding WebimConfig.cs ---------------------- You should change the WebimConfig.java, and load configurations from database or xml. Webim Javascript ----------------------- Insert Javascript code below to web pages that need to display Webim: [removed][removed]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值