目录
一、项目展示
二、项目创建
创建文件夹使用VsCode打开后,新建终端输入以下命令
打开UI创建项目
npm install -g @vue/cli # 安装vue
vue -ui # 在浏览器创建项目
UI创建步骤
配置端口与代理
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
port: 9898,
proxy: {
'/api': {
target: "http://localhost:9897",
changeOrigin: true
}
}
}
})
三、Vue语法
文本插值
<template>
<div id="app">
{
{problems[0].id + problems[1].id}} {
{problems[0].title}} {
{problems[0].level}}
{
{problems[0].level === "easy" ? "easy" : "other"}}
</div>
</template>
<script>
const options = {
data: function () {
return {
problems: [
{id: 1, title: "两数之和1", level: "easy"},
{id: 2, title: "两数之和2", level: "easy"},
{id: 3, title: "两数之和3", level: "easy"}
]
};
}
};
export default options;
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style>
属性绑定
<template>
<div id="app">
<input type="text" v-bind:value="name">
<input type="text" :value="name">
</div>
</template>
<script>
const options = {
data: function () {
return {
name: "王五"
};
}
};
export default options;
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style>
事件绑定
<template>
<div id="app">
<input type="button" v-bind:value="msg" v-on:click="login">
<input type="button" v-bind:value="msg" @click="login">
</div>
</template>
<script>
const options = {
data: function () {
return {
msg: "点我"
};
},
methods: {
login: function () {
alert(options.data().msg)
}
}
};
export default options;
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
}
nav a {
font-weight: bold;
color: #2c3e50;
}
nav a.router-link-exact-active {
color: #42b983;
}
</style>