Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
83471447
U
uni-app
项目概览
DCloud
/
uni-app
大约 2 个月 前同步成功
通知
711
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
83471447
编写于
8月 24, 2019
作者:
W
wangyaqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: WXS部分增加sjs、filter时间格式化示例
上级
1bfdd413
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
90 addition
and
1 deletion
+90
-1
docs/frame.md
docs/frame.md
+90
-1
未找到文件。
docs/frame.md
浏览文件 @
83471447
...
...
@@ -993,7 +993,96 @@ WXS是微信小程序的一套脚本语言,[详见](https://developers.weixin.
}
</style>
```
支付宝小程序,百度小程序官方暂未支持事件响应,不过也可以使用对应的SJS、Filter过滤器实现一些方便的操作,以下代码展示了一个时间格式化的小功能
```
index.vue
```
```
<template>
<view>
<view>
{{timestr}} 是
</view>
<view>
{{utils.friendlyDate(timestamp)}}
</view>
</view>
</template>
<filter
module=
"utils"
src=
"./utils.filter.js"
></filter>
<import-sjs
module=
"utils"
src=
"./utils.sjs"
/>
<script>
export default {
data() {
return {
timestr: '2019/08/22 10:10:10',
timestamp: 0
}
},
created() {
this.timestamp = new Date(this.timestr).getTime()
},
methods: {
}
}
</script>
```
```
utils.sjs
```与```
utils.filter.js
```
```
export default {
friendlyDate: (timestamp) => {
var formats = {
'year': '%n% 年前',
'month': '%n% 月前',
'day': '%n% 天前',
'hour': '%n% 小时前',
'minute': '%n% 分钟前',
'second': '%n% 秒前',
};
var now = Date.now();
var seconds = Math.floor((now - parseInt(timestamp)) / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var months = Math.floor(days / 30);
var years = Math.floor(months / 12);
var diffType = '';
var diffValue = 0;
if (years > 0) {
diffType = 'year';
diffValue = years;
} else {
if (months > 0) {
diffType = 'month';
diffValue = months;
} else {
if (days > 0) {
diffType = 'day';
diffValue = days;
} else {
if (hours > 0) {
diffType = 'hour';
diffValue = hours;
} else {
if (minutes > 0) {
diffType = 'minute';
diffValue = minutes;
} else {
diffType = 'second';
diffValue = seconds === 0 ? (seconds = 1) : seconds;
}
}
}
}
}
return formats[diffType].replace('%n%', diffValue);
}
}
```
**注意**
...
...
@@ -1004,7 +1093,7 @@ WXS是微信小程序的一套脚本语言,[详见](https://developers.weixin.
- 百度小程序中请使用Filter过滤器,[详见](https://smartprogram.baidu.com/docs/develop/framework/view_filter/)
- 百度小程序Filter只能导出function函数
- 暂不支持在 wxs、sjs、filter.js 中调用其他同类型文件
- 编写wxs、sjs、filter.js 内容时必须遵循相应语法规范
- 编写wxs、sjs、filter.js 内容时必须遵循相应语法规范
**重要**
- wxs、filter.js既能内联使用又可以外部引入,sjs只能外部引入
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录