提交 025da8bb 编写于 作者: 郭维嘉

feat:初始化项目,添加keyboard组件

上级 1d14eb53
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view />
</div>
</template>
......@@ -16,17 +12,4 @@
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
const keys = [
// 第一行
{ id: 1, type: "Letter", primaryName: "`", subName: "~" },
{ id: 1, type: "Letter", primaryName: "1", subName: "!" },
{ id: 1, type: "Letter", primaryName: "2", subName: "@" },
{ id: 1, type: "Letter", primaryName: "3", subName: "#" },
{ id: 1, type: "Letter", primaryName: "4", subName: "$" },
{ id: 1, type: "Letter", primaryName: "5", subName: "%" },
{ id: 1, type: "Letter", primaryName: "6", subName: "^" },
{ id: 1, type: "Letter", primaryName: "7", subName: "&" },
{ id: 1, type: "Letter", primaryName: "8", subName: "*" },
{ id: 1, type: "Letter", primaryName: "9", subName: "(" },
{ id: 1, type: "Letter", primaryName: "0", subName: ")" },
{ id: 1, type: "Letter", primaryName: "-", subName: "" },
{ id: 1, type: "Letter", primaryName: "=", subName: "+" },
{ id: 1, type: "Backspace", primaryName: "Backspace", subName: "" },
// 第二行
{ id: 1, type: "Tab", primaryName: "Tab", subName: "" },
{ id: 1, type: "Letter", primaryName: "Q", subName: "" },
{ id: 2, type: "Letter", primaryName: "W", subName: "" },
{ id: 3, type: "Letter", primaryName: "E", subName: "" },
{ id: 4, type: "Letter", primaryName: "R", subName: "" },
{ id: 4, type: "Letter", primaryName: "T", subName: "" },
{ id: 4, type: "Letter", primaryName: "Y", subName: "" },
{ id: 4, type: "Letter", primaryName: "U", subName: "" },
{ id: 4, type: "Letter", primaryName: "I", subName: "" },
{ id: 4, type: "Letter", primaryName: "O", subName: "" },
{ id: 4, type: "Letter", primaryName: "P", subName: "" },
{ id: 4, type: "Letter", primaryName: "[", subName: "" },
{ id: 4, type: "Letter", primaryName: "]", subName: "" },
{ id: 4, type: "Letter", primaryName: "\\", subName: "|" },
// 第三行
{ id: 4, type: "Caps Lock", primaryName: "Caps Lock", subName: "" },
];
export default keys;
*,
html,
body {
padding: 0;
margin: 0;
}
.col-3 {
width: 25%;
}
.col-9 {
width: 75%;
}
*,
html,
body {
padding: 0;
margin: 0;
}
.col-3 {
width: 25%;
}
.col-9 {
width: 75%;
}
@keyboard-bg-color: #dfd9d9;
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br />
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener"
>vue-cli documentation</a
>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
target="_blank"
rel="noopener"
>babel</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router"
target="_blank"
rel="noopener"
>router</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex"
target="_blank"
rel="noopener"
>vuex</a
>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
target="_blank"
rel="noopener"
>eslint</a
>
</li>
</ul>
<h3>Essential Links</h3>
<ul>
<li>
<a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a>
</li>
<li>
<a href="https://forum.vuejs.org" target="_blank" rel="noopener"
>Forum</a
>
</li>
<li>
<a href="https://chat.vuejs.org" target="_blank" rel="noopener"
>Community Chat</a
>
</li>
<li>
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener"
>Twitter</a
>
</li>
<li>
<a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a>
</li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li>
<a href="https://router.vuejs.org" target="_blank" rel="noopener"
>vue-router</a
>
</li>
<li>
<a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-devtools#vue-devtools"
target="_blank"
rel="noopener"
>vue-devtools</a
>
</li>
<li>
<a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener"
>vue-loader</a
>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
rel="noopener"
>awesome-vue</a
>
</li>
</ul>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
<template>
<div class="key" :style="{ width: keyWidth + 'px' }">
<div class="multiple" v-if="subName">
<span v-html="subName"></span>
<span v-html="primaryName"></span>
</div>
<span v-else v-html="primaryName"></span>
</div>
</template>
<script>
export default {
props: {
type: {
type: String,
default: "",
},
primaryName: {
type: String,
default: "",
},
subName: {
type: String,
defualt: "",
},
},
computed: {
keyWidth() {
let keyWidth = 44;
const keyType = this.type;
if (!keyType) return keyWidth;
switch (keyType) {
case "Letter":
keyWidth = 44;
break;
case "Tab":
keyWidth = 72;
break;
case "Caps Lock":
keyWidth = 82;
break;
case "Backspace":
keyWidth = 94;
break;
default:
break;
}
return keyWidth;
},
},
data() {
return {};
},
};
</script>
<style lang="less" scoped>
.key {
height: 44px;
line-height: 44px;
background: skyblue;
border-radius: 4px;
margin: 2px;
.multiple {
display: flex;
flex-direction: column;
justify-content: space-around;
height: 100%;
span {
line-height: 1em;
}
}
}
</style>
<template>
<div class="keyboard">
<key v-for="(item, index) in list" :key="index" v-bind="item" />
</div>
</template>
<script>
import key from "@/components/key.vue";
import mock from "@/assets/js/mock";
export default {
components: { key },
data() {
return {
list: mock
};
},
};
</script>
<style lang="less" scoped>
.keyboard {
width: 722px;
margin: 80px auto;
padding: 20px;
background: @keyboard-bg-color;
border-radius: 10px;
display: flex;
flex-wrap: wrap;
}
</style>
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
Vue.use(VueRouter);
......@@ -8,16 +7,7 @@ const routes = [
{
path: "/",
name: "Home",
component: Home
},
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue")
component: () => import("@/views/index.vue")
}
];
......
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
export default {
name: "Home",
components: {
HelloWorld
}
};
</script>
<template>
<div class="index">
<div class="col-9">
<keyboard />
</div>
<div class="col-3"></div>
</div>
</template>
<script>
import keyboard from "@/components/keyboard.vue";
export default {
name: "Home",
components: { keyboard }
};
</script>
<style lang="less" scoped>
.index {
display: flex;
justify-content: space-between;
}
</style>
const path = require("path");
module.exports = {
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: [path.resolve(__dirname, "./src/assets/style/global.less")]
}
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册