<template>
<div id="home">
{{name}} {{pwd}}
<div>
<p>文本插值 {{message}}</p>
<p>JS 表达式 {{flag ? 'yes' : 'no'}}</p>
<p :id="dynamicId">动态属性 id</p>
<hr />
<p v-html="rawHtml">
<span>有 xss 风险</span>
<span>使用 v-html 之后,将会覆盖子元素</span>
</p>
</div>
</div>
</template>
<script>
function generateOrderNumber(length = 4) {
const now = new Date();
let year = now.getFullYear().toString();
let month = (now.getMonth() + 1).toString();
console.log(now.getMonth(), "999999999999");
let day = now.getDate().toString();
let hour = now.getHours().toString();
let minutes = now.getMinutes().toString();
let seconds = now.getSeconds().toString();
// 存放订单号
let num = "";
// N位随机数(加在时间戳后面)
for (var i = 0; i < length; i++) {
num += Math.floor(Math.random() * 10);
console.log(num);
}
return year + month + day + hour + minutes + seconds + num;
}
//调用示例
console.log(generateOrderNumber());
console.log("Home.vue...");
var now = new Date();
console.log(now, "00000000000000000000");
var date = new Date();
console.log(date.getFullYear()); // 2022 返回当前日期的年=
console.log(date.getMonth() + 1); //4 月份 返回的月份少1 所以要+1
var tt = date.getMonth() + 1;
console.log(tt > 10 ? tt : "0" + tt, "1111111111111111111");
console.log(date.getDate()); //16 返回当前的日期
console.log(date.getDay()); //6 周一返回的是1 周六返回的是6 周日返回的是0
// 要写一个2022年4月16日 星期六
var year = date.getFullYear();
var month = date.getMonth() + 1;
var dates = date.getDate();
var day = date.getDay();
var arr = [
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
];
console.log("今天是:" + year + "年" + month + "月" + dates + "日 " + arr[day]);
export default {
data() {
return {
name: "",
pwd: "",
message: "hello vue",
flag: true,
rawHtml: "指令 - 原始 html <b>加粗</b> <i>斜体</i>",
dynamicId: `id-${Date.now()}`,
};
},
created() {
let { name, pwd } = this.$route.params;
this.name = name;
this.pwd = pwd;
},
};
</script>
<style>
</style>