前端界面初始化

master
barney 2 years ago
parent 8e1a25a9c0
commit 7f08beda6d
  1. BIN
      db.sqlite3
  2. 16
      drf_vue_blog/settings.py
  3. 23
      frontend/.gitignore
  4. 24
      frontend/README.md
  5. 5
      frontend/babel.config.js
  6. 19
      frontend/jsconfig.json
  7. 19391
      frontend/package-lock.json
  8. 45
      frontend/package.json
  9. BIN
      frontend/public/favicon.ico
  10. 17
      frontend/public/index.html
  11. 29
      frontend/src/App.vue
  12. 73
      frontend/src/components/ArticleList.vue
  13. 27
      frontend/src/components/BlogFooter.vue
  14. 22
      frontend/src/components/BlogHeader.vue
  15. 4
      frontend/src/main.js
  16. 4
      frontend/vue.config.js

Binary file not shown.

@ -32,16 +32,19 @@ INSTALLED_APPS = [
'user_info',
'django_filters',
'comment',
'corsheaders'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'drf_vue_blog.urls'
@ -139,3 +142,16 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# 'ACCESS_TOKEN_LIFETIME': timedelta(days=1), # 令牌有效时间为1天
# 'REFRESH_TOKEN_LIFETIME': timedelta(days=10), # 令牌每10天刷新一次
# }
#将允许将cookie包含在跨站点HTTP请求中
CORS_ALLOW_CREDENTIALS = True
#添加允许执行跨站点请求的主机,为True,则将不使用白名单,并且将接受所有来源
CORS_ORIGIN_ALLOW_ALL = True
# 允许所有的请求头
CORS_ALLOW_HEADERS = ('*')
CORS_ALLOWED_ORIGINS = (
'http://127.0.0.1:8080',
'http://localhost:8080'
)

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -0,0 +1,24 @@
# frontend
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,45 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.27.2",
"core-js": "^3.8.3",
"jquery": "^3.6.1",
"vue": "^3.2.13"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

@ -0,0 +1,29 @@
<template>
<BlogHeader />
<ArticleList />
<BlogFooter />
</template>
<script>
import ArticleList from '@/components/ArticleList.vue'
import BlogHeader from '@/components/BlogHeader.vue'
import BlogFooter from '@/components/BlogFooter.vue'
export default {
name: 'App',
components: {
ArticleList,
BlogHeader,
BlogFooter,
}
}
</script>
<style>
#app {
font-family: Georgia, Arial, sans-serif;
margin-left: 40px;
margin-right: 40px;
}
</style>

@ -0,0 +1,73 @@
<template>
<div v-for="article in articles" :key="article.url" id="articles">
<span
v-for="tag in article.tags"
v-bind:key="tag"
class="tag"
>
{{ tag }}
</span>
<div class="article-title">
{{ article.title }}
</div>
{{ formatted_time(article.created) }}
</div>
</template>
<script>
import $ from 'jquery'
import { ref } from 'vue'
export default {
name: "ArticleList",
setup() {
let articles = ref([]);
$.ajax({
url: "http://127.0.0.1:6789/api/article/",
type: "GET",
success: resp => {
articles.value = resp.results
}
});
const formatted_time = (iso_date_string) => {
const date = new Date(iso_date_string);
return date.toLocaleDateString()
};
return {
articles,
formatted_time,
}
}
}
</script>
<style scoped>
#articles {
padding: 10px;
}
.article-title {
font-size: large;
font-weight: bolder;
color: black;
text-decoration: none;
padding: 5px 0 5px 0;
}
.tag {
padding: 2px 5px 2px 5px;
margin: 5px 5px 5px 0;
font-family: Georgia, Arial, sans-serif;
font-size: small;
background-color: #4e4e4e;
color: whitesmoke;
border-radius: 5px;
}
</style>

@ -0,0 +1,27 @@
<template>
<div id="footer">
<p>&copy; bnblogs.cc</p>
</div>
</template>
<script>
export default {
name: "BlogFooter",
}
</script>
<style scoped>
#footer {
position: fixed;
left: 0;
bottom: 0;
height: 50px;
width: 100%;
background: whitesmoke;
text-align: center;
font-weight: bold;
}
</style>

@ -0,0 +1,22 @@
<template>
<div id="header">
<h1>My Drf-Vue Blog</h1>
<hr>
</div>
</template>
<script>
export default {
name: "BlogHeader",
}
</script>
<style scoped>
#header {
text-align: center;
margin-top: 20px;
}
</style>

@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')

@ -0,0 +1,4 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
Loading…
Cancel
Save