Vue前端判断数据对象是否为空的实例
作者:shokang 时间:2024-05-02 16:53:14
看代码:
Vue提供了强大的前端开发架构,很多时候我们需要判断数据对象是否为空,使用typeof判断是个不错选择,具体代码见图。
补充知识:vue打包后 history模式 跟子目录 静态文件路径 分析
history
根目录
路由mode变为history后,需要在服务器配置 url重写,在根目录 创建web.config文件 加下面内容复制进去
<?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="/static/logo.png" alt="" srcset=""> 跟路径 / 和 相对路径
<div class="image1" style="background:url('../static/logo.png')"></div> 跟路径 / 和 ../
<img :src="image" alt="" srcset=""> 跟路径 / 和../
data () {
return {
image: '../static/logo.png'
}
}
子目录
例如我在根目录下创建子目录名为app的文件夹作为项目文件夹
路由mode变为history后,需要在服务器配置 url重写,在根目录 创建web.config文件 加下面内容复制进去 与根目录不同的是
action 标签 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 从默认的 / 改成 自己部署的 子目录名称 /app/
build: {
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/app/',
}
router.js 需要改下 base 根据不同的打包环境 dev 默认就是 / pro需要根据项目路径
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="../../static/logo.png" alt="" srcset=""> 相对路径
<div class="image1" style="background:url('../static/logo.png')"></div> ../
<img :src="image" alt="" srcset=""> ../
data () {
return {
image: '../static/logo.png'
}
}
总结:
history模式,本地运行 肯定是在根目录 127.0.0.1:xxxx/# 使用上面根目录方法
打包发到生产环境,视情况使用
根目录和子目录 有些相同的引入方法
建议 直接使用相同的方法 同时适应根目录和子目录 部署
background: url('../../static/logo.png') no-repeat center/ 50%; 相对路径
<img src="../../static/logo.png" alt="" srcset=""> 相对路径
<div class="image1" style="background:url('../static/logo.png')"></div> ../
<img :src="image" alt="" srcset=""> ../
data () {
return {
image: '../static/logo.png'
}
}
来源:https://blog.csdn.net/shokang/article/details/89632706
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
sqlserver 数据库连接字符串中的可选项收集
连接无法用于执行此操作。在此上下文中它可能已被关闭或无效
Python实现获取视频时长功能
![](https://img.aspxhome.com/file/2023/0/80420_0s.png)
Django操作cookie的实现
![](https://img.aspxhome.com/file/2023/1/77011_0s.jpg)
python Pandas如何对数据集随机抽样
![](https://img.aspxhome.com/file/2023/9/95509_0s.png)
oracle数据库tns配置方法详解
![](https://img.aspxhome.com/file/2023/7/63367_0s.png)
python中正则表达式与模式匹配
![](https://img.aspxhome.com/file/2023/2/97132_0s.png)
基于python+selenium自动健康打卡的实现代码
![](https://img.aspxhome.com/file/2023/0/90780_0s.png)
遗传算法之Python实现代码
http状态码一览表以及HTTP响应的返回头信息
Python中http请求方法库汇总
Django 视图层(view)的使用
Oracle 的入门心得 强烈推荐
深入浅析Django MTV模式
![](https://img.aspxhome.com/file/2023/3/75143_0s.png)
python使用sessions模拟登录淘宝的方式
pandas库中 DataFrame的用法小结
![](https://img.aspxhome.com/file/2023/4/87894_0s.png)
python进度条库tqdm的基本操作方法
基于Python Pygame实现的画饼图游戏
![](https://img.aspxhome.com/file/2023/4/95864_0s.gif)
文字的减法
深入理解PyTorch中的nn.Embedding的使用
![](https://img.aspxhome.com/file/2023/8/117418_0s.png)