欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2020年09月02日 09:21:35   作者:shokang  
這篇文章主要介紹了Vue前端判斷數(shù)據(jù)對(duì)象是否為空的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

看代碼:

Vue提供了強(qiáng)大的前端開發(fā)架構(gòu),很多時(shí)候我們需要判斷數(shù)據(jù)對(duì)象是否為空,使用typeof判斷是個(gè)不錯(cuò)選擇,具體代碼見圖。

補(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="/static/logo.png" alt="" srcset=""> 跟路徑 / 和 相對(duì)路徑

<div class="image1" style="background:url('../static/logo.png')"></div> 跟路徑 / 和 ../

<img :src="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="../../static/logo.png" alt="" srcset=""> 相對(duì)路徑

<div class="image1" style="background:url('../static/logo.png')"></div> ../

<img :src="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="../../static/logo.png" alt="" srcset=""> 相對(duì)路徑

<div class="image1" style="background:url('../static/logo.png')"></div> ../

<img :src="image" alt="" srcset=""> ../
data () {
 return {
 image: '../static/logo.png'
 }
}

以上這篇Vue前端判斷數(shù)據(jù)對(duì)象是否為空的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論