Vue前端判斷數(shù)據(jù)對象是否為空的實例
看代碼:
Vue提供了強大的前端開發(fā)架構(gòu),很多時候我們需要判斷數(shù)據(jù)對象是否為空,使用typeof判斷是個不錯選擇,具體代碼見圖。
補充知識:vue打包后 history模式 跟子目錄 靜態(tài)文件路徑 分析
history
根目錄
路由mode變?yōu)閔istory后,需要在服務(wù)器配置 url重寫,在根目錄 創(chuàng)建web.config文件 加下面內(nèi)容復(fù)制進去
<?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.piao2010.com/static/logo.png' alt='' srcset=''> 跟路徑 / 和 相對路徑
<div style='background:url(’../static/logo.png’)'></div> 跟路徑 / 和 ../
<img :src='http://www.piao2010.com/bcjs/image' alt='' srcset=''> 跟路徑 / 和../data () { return { image: ’../static/logo.png’ }}
子目錄
例如我在根目錄下創(chuàng)建子目錄名為app的文件夾作為項目文件夾
路由mode變?yōu)閔istory后,需要在服務(wù)器配置 url重寫,在根目錄 創(chuàng)建web.config文件 加下面內(nèi)容復(fù)制進去 與根目錄不同的是
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ù)項目路徑
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.piao2010.com/static/logo.png' alt='' srcset=''> 相對路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.piao2010.com/bcjs/image' alt='' srcset=''> ../data () { return { image: ’../static/logo.png’ }}
總結(jié):
history模式,本地運行 肯定是在根目錄 127.0.0.1:xxxx/# 使用上面根目錄方法
打包發(fā)到生產(chǎn)環(huán)境,視情況使用
根目錄和子目錄 有些相同的引入方法
建議 直接使用相同的方法 同時適應(yīng)根目錄和子目錄 部署
background: url(’../../static/logo.png’) no-repeat center/ 50%; 相對路徑
<img src='http://www.piao2010.com/static/logo.png' alt='' srcset=''> 相對路徑
<div style='background:url(’../static/logo.png’)'></div> ../
<img :src='http://www.piao2010.com/bcjs/image' alt='' srcset=''> ../data () { return { image: ’../static/logo.png’ }}
以上這篇Vue前端判斷數(shù)據(jù)對象是否為空的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識)2. ASP.NET MVC實現(xiàn)登錄后跳轉(zhuǎn)到原界面3. Python如何解決secure_filename對中文不支持問題4. 不使用XMLHttpRequest對象實現(xiàn)Ajax效果的方法小結(jié)5. ASP.NET MVC限制同一個IP地址單位時間間隔內(nèi)的請求次數(shù)6. Python使用oslo.vmware管理ESXI虛擬機的示例參考7. 怎樣打開XML文件?xml文件如何打開?8. ThinkPHP6使用JWT+中間件實現(xiàn)Token驗證實例詳解9. TP5使用RabbitMQ實現(xiàn)消息隊列的項目實踐10. JSP出現(xiàn)中文亂碼問題解決方法詳解
