Vue前端判斷數(shù)據(jù)對(duì)象是否為空的實(shí)例
看代碼:

Vue提供了強(qiáng)大的前端開發(fā)架構(gòu),很多時(shí)候我們需要判斷數(shù)據(jù)對(duì)象是否為空,使用typeof判斷是個(gè)不錯(cuò)選擇,具體代碼見(jiàn)圖。
補(bǔ)充知識(shí):vue打包后 history模式 跟子目錄 靜態(tài)文件路徑 分析
history
根目錄
路由mode變?yōu)閔istory后,需要在服務(wù)器配置 url重寫,在根目錄 創(chuàng)建web.config文件 加下面內(nèi)容復(fù)制進(jìn)去
<?xml version='1.0' encoding='utf-8'?><configuration> <system.webServer> <rewrite> <rules> <rule name='Handle History Mode and custom 404/500' stopProcessing='true'> <match url='(.*)' /> <conditions logicalGrouping='MatchAll'> <add input='{REQUEST_FILENAME}' matchType='IsFile' negate='true' /> <add input='{REQUEST_FILENAME}' matchType='IsDirectory' negate='true' /> </conditions> <action type='Rewrite' url='/index.html' /> </rule> </rules> </rewrite> </system.webServer></configuration>
background: url(’/static/logo.png’) no-repeat center/ 50%; 跟路徑 / 和 相對(duì)路徑
<img src='http://www.intensediesel.com/static/logo.png' alt='' srcset=''> 跟路徑 / 和 相對(duì)路徑
<div style='background:url(’../static/logo.png’)'></div> 跟路徑 / 和 ../
<img :src='http://www.intensediesel.com/bcjs/image' alt='' srcset=''> 跟路徑 / 和../data () { return { image: ’../static/logo.png’ }}
子目錄
例如我在根目錄下創(chuàng)建子目錄名為app的文件夾作為項(xiàng)目文件夾
路由mode變?yōu)閔istory后,需要在服務(wù)器配置 url重寫,在根目錄 創(chuàng)建web.config文件 加下面內(nèi)容復(fù)制進(jìn)去 與根目錄不同的是
action 標(biāo)簽 url /app/index.html
<?xml version='1.0' encoding='utf-8'?><configuration> <system.webServer> <rewrite> <rules> <rule name='Handle History Mode and custom 404/500' stopProcessing='true'> <match url='(.*)' /> <conditions logicalGrouping='MatchAll'> <add input='{REQUEST_FILENAME}' matchType='IsFile' negate='true' /> <add input='{REQUEST_FILENAME}' matchType='IsDirectory' negate='true' /> </conditions> <action type='Rewrite' url='/app/index.html' /> </rule> </rules> </rewrite> </system.webServer></configuration>
config index.js文件下 build對(duì)象中publicPatch 從默認(rèn)的 / 改成 自己部署的 子目錄名稱 /app/
build: { // Paths assetsRoot: path.resolve(__dirname, ’../dist’), assetsSubDirectory: ’static’, assetsPublicPath: ’/app/’,}
router.js 需要改下 base 根據(jù)不同的打包環(huán)境 dev 默認(rèn)就是 / pro需要根據(jù)項(xiàng)目路徑
var base = process.env.NODE_ENV === ’development’ ? ’/’ : ’/app/’export default new Router({ mode: ’history’, base: base, routes: []})
background: url(’../../static/logo.png’) no-repeat center/ 50%; 相對(duì)路徑
<img src='http://www.intensediesel.com/static/logo.png' alt='' srcset=''> 相對(duì)路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.intensediesel.com/bcjs/image' alt='' srcset=''> ../data () { return { image: ’../static/logo.png’ }}
總結(jié):
history模式,本地運(yùn)行 肯定是在根目錄 127.0.0.1:xxxx/# 使用上面根目錄方法
打包發(fā)到生產(chǎn)環(huán)境,視情況使用
根目錄和子目錄 有些相同的引入方法
建議 直接使用相同的方法 同時(shí)適應(yīng)根目錄和子目錄 部署
background: url(’../../static/logo.png’) no-repeat center/ 50%; 相對(duì)路徑
<img src='http://www.intensediesel.com/static/logo.png' alt='' srcset=''> 相對(duì)路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.intensediesel.com/bcjs/image' alt='' srcset=''> ../data () { return { image: ’../static/logo.png’ }}
以上這篇Vue前端判斷數(shù)據(jù)對(duì)象是否為空的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JS圖片懶加載庫(kù)VueLazyLoad詳解2. Java實(shí)現(xiàn)的迷宮游戲3. django queryset相加和篩選教程4. Java利用TCP協(xié)議實(shí)現(xiàn)客戶端與服務(wù)器通信(附通信源碼)5. idea設(shè)置提示不區(qū)分大小寫的方法6. Java PreparedStatement用法詳解7. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算8. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶登錄的步驟9. Spring如何集成ibatis項(xiàng)目并實(shí)現(xiàn)dao層基類封裝10. IDEA 2020.1.2 安裝教程附破解教程詳解

網(wǎng)公網(wǎng)安備