Vue前端判斷數(shù)據(jù)對象是否為空的實(shí)例
看代碼:
Vue提供了強(qiáng)大的前端開發(fā)架構(gòu),很多時(shí)候我們需要判斷數(shù)據(jù)對象是否為空,使用typeof判斷是個(gè)不錯(cuò)選擇,具體代碼見圖。
補(bǔ)充知識: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%; 跟路徑 / 和 相對路徑
<img src='http://www.aoyou183.cn/static/logo.png' alt='' srcset=''> 跟路徑 / 和 相對路徑
<div style='background:url(’../static/logo.png’)'></div> 跟路徑 / 和 ../
<img :src='http://www.aoyou183.cn/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對象中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%; 相對路徑
<img src='http://www.aoyou183.cn/static/logo.png' alt='' srcset=''> 相對路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.aoyou183.cn/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%; 相對路徑
<img src='http://www.aoyou183.cn/static/logo.png' alt='' srcset=''> 相對路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.aoyou183.cn/bcjs/image' alt='' srcset=''> ../data () { return { image: ’../static/logo.png’ }}
以上這篇Vue前端判斷數(shù)據(jù)對象是否為空的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟2. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)3. css代碼優(yōu)化的12個(gè)技巧4. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算5. 教你如何寫出可維護(hù)的JS代碼6. IDEA版最新MyBatis程序配置教程詳解7. 使用Python和百度語音識別生成視頻字幕的實(shí)現(xiàn)8. idea不能自動(dòng)補(bǔ)全yml配置文件的原因分析9. phpstudy apache開啟ssi使用詳解10. .NET SkiaSharp 生成二維碼驗(yàn)證碼及指定區(qū)域截取方法實(shí)現(xiàn)
