first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
</head>
<body>
<div class="app">
<h1>Hello App!</h1>
<p>
<!-- 使用 router-link 组件来导航. -->
<!-- 通过传入 `to` 属性指定链接. -->
<!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
<router-link to="/">Go to 首页</router-link>
<router-link to="/bar">Go to Bar</router-link>
<router-link to="/Info">Go to Info</router-link>
</p>
<!-- 路由出口 -->
<!-- 路由匹配到的组件将渲染在这里 -->
<router-view></router-view>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script>
// 0. 如果使用模块化机制编程,导入Vue和VueRouter,要调用 Vue.use(VueRouter)
// 1. 定义 (路由) 组件。
// 可以从其他文件 import 进来
const Index = {
data() {
return {
list: [
{ id: 1, title: '新闻1' },
{ id: 2, title: '新闻2' },
{ id: 3, title: '新闻3' }
]
}
},
// js跳转页面 在to里面填地址(例: :to={"path:'/Info',参数(quer(query:{id:v.id})或者params传参数)}")
// quer传参: :to={"path:'/Info',query:{id:v.id,page:1}}"
// params传参:params:{id:v.id,page:1} > 然后const routes中的 path改为: '/Info/:id/:page' 加一个name: 'Info'
template: `
<div class="index">
首页
<ul>
<li @click="enterInfo(i)" v-for="v,i in list" :key="i">{{v.title}}</li>
</ul>
</div>
`,
// <router-link tag="a" :to="{name:'Info',params:{id:v.id,page:1}}" v-for="v,i in list">{{v.title}}</router-link> router-link页面跳转写法
methods: {
enterInfo(v) {
this.$router.push({
name: 'Info',
query: {
id: v.id,
page: 1
}
})
}
}
}
const Bar = { template: '<div>bar</div>' }
const Info = {
template: '<div>详情页{{$route.params.id}}</div>',
data() {
return {
// id: 0
}
},
// query传参把参数渲染到页面上
// 方法1 :data的return定义一个变量默认为0 > created中this.xx = this.$route.query.xx > template中: '<div>详情页{{xx}}</div>'
// 方法2 :直接在template中写: '<div>详情页{{$route.query.xx}}</div>',
// params传参把参数渲染到页面上 就是把query的方法中的query改为params
created() {
// this.id = this.$route.query.id
// 拿到地址栏参数的方法
console.log(this.$route.query.id);
},
methods: {}
}
// 2. 定义路由
// 每个路由应该映射一个组件。 其中"component" 可以是
// 通过 Vue.extend() 创建的组件构造器,
// 或者,只是一个组件配置对象。
// 我们晚点再讨论嵌套路由。
const routes = [
{ path: '/', component: Index },
{ path: '/bar', component: Bar },
{
path: '/Info', component: Info, name: 'Info'
// params传参写法 path: '/Info/:id/:page', component: Info, name: 'Info'
}
]
// 3. 创建 router 实例,然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
mode: 'hash',
routes // (缩写) 相当于 routes: routes
})
// 导航守卫
router.beforeEach((to, from, next) => {
})
// 4. 创建和挂载根实例。
// 记得要通过 router 配置参数注入路由,
// 从而让整个应用都有路由功能
const app = new Vue({
el: '.app',
router
})//.$mount('#app')也可以挂载或el
// 现在,应用已经启动了!
</script>
</html>

View File

@@ -0,0 +1,189 @@
<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
<style>
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.title {
display: flex;
}
.title li {
margin-right: 10px;
}
.title .active {
color: red;
}
.content li {
display: none;
}
.content .active {
display: block;
}
</style>
</head>
<body>
<div class="add">
<!-- <ul class="title">
<li :class=" i == index ? 'active' : '' " v-for="v,i in arr" @click="index = i" :key="i">
{{ v.title }}
</li>
</ul>
<ul class="content">
<li :class=" i == index ? 'active' : '' " v-for="v,i in arr" :key="i">
<p v-for="item,index in v.content">{{ item.text }}</p>
</li>
</ul> -->
<p>{{text}}</p>
<p v-text="imgSrc"></p>
<!-- v-html -->
<div v-html="imgSrc"></div>
<p></p>
<!-- v-for -->
<ul>
<li v-for="v,i in news">{{v.id}}|{{v.title}}</li>
</ul>
<p></p>
<div v-for="value,key in obj">{{key}}:{{value}}</div>
<!-- v-bind 简写‘:’ -->
<img :src="img" alt="">
<!-- v-if -->
<div v-if="type==0">一级会员</div>
<div v-else-if="type==1">二级会员</div>
<div v-else>请登录</div> <!-- <div v-else="type==2">请登录</div> -->
<!-- v-show -->
<div v-show="show">嘻嘻嘻</div>
<p></p>
<!-- v-model (input、select、textarea都适用)-->
<input type="text" placeholder="请输入" v-model="name">{{name}}
<p></p>
<!-- v-on 简写‘@’ -->
<button v-on:click="Button">登录</button>
<!-- <button @click="Button">登录</button> -->
<p></p>
<!-- tab切换 -->
<!-- <ul class="title">
<li :class="i==Index?'active':''" v-for="v,i in arr" :key="i" @click="change(i)">{{v.title}}</li>
</ul>
<ul class="content">
<li :class="i==Index?'active':''" v-for="v,i in arr" :key="i">
<p v-for="ele,index in v.content" :key="index">{{ele.text}}</p>
</li>
</ul> -->
<ul class="title">
<li :class="i==Index?'active':''" v-for="v,i in arr" :key="i" @click="change(i)">{{v.title}}</li>
</ul>
<ul class="content">
<li :class="i==Index?'active':''" v-for="v,i in arr" :key="i">
<p v-for="a,b in v.content">{{a.text}}</p>
</li>
</ul>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
<script>
new Vue({
el: ".add",
data: {
// index: 0,
arr: [
{
title: '首页',
content: [
{ text: '首页的内容1' },
{ text: '首页的内容2' },
{ text: '首页的内容3' },
{ text: '首页的内容4' },
{ text: '首页的内容5' },
]
},
{
title: '社会',
content: [
{ text: '社会 的内容1' },
{ text: '社会 的内容2' },
{ text: '社会 的内容3' },
{ text: '社会 的内容4' },
]
},
{
title: '军事',
content: [
{ text: '军事 的内容1' },
{ text: '军事 的内容2' },
{ text: '军事 的内容3' },
]
},
{
title: '科技',
content: [
{ text: '科技 的内容1' },
{ text: '科技 的内容2' },
{ text: '科技 的内容3' },
]
}
],
text: '1111',
imgSrc: `<img src="https://www.baidu.com/img/flexible/logo/pc/result.png" alt="">`,
news: [
{ id: 1, title: 'a' },
{ id: 2, title: 'b' },
{ id: 3, title: 'c' }
],
obj: { id: 1, title: 'a' },
img: 'https://www.baidu.com/img/flexible/logo/pc/result.png',
type: 2,
show: false,
name: '',
Index: 0
},
// 所有方法存放地方
methods: {
Button() {
console.log("Button:", this.name);
},
// change(index) {
// this.index = index
// }
change(index) {
this.Index = index
console.log(index);
}
}
})
</script>
</html>

View File

@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
</head>
<div class="app">
<abc @change="getData" ></abc>
<!-- :x=" '2' " -->
<!-- <c></c>
<d></d> -->
</div>
<body>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
Vue.component('abc', {
template: `
<div>
<h1>{{title}}</h1>
<h2 @click="submit">{{ x }}</h2>
</div>`,
data() {
return {
title: '我是全局组件',
list: "这是子组件的数据"
}
},
props: {
x: {
default: "这是默认标题",
type: String
}
},
methods: {
submit() {
this.$emit("change", this.list)
}
}
})
// var c = {
// template: `<h1>{{title}}</h1>`,
// data() {
// return {
// title: '我是局部组件',
// }
// }
// }
new Vue({
el: ".app",
data: {},
methods: {
getData(val) {
console.log("父组件收到的数据:", val);
}
},
// components: {
// c,
// "d": c
// }
})
</script>
</html>

View File

@@ -0,0 +1,117 @@
<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
</head>
<body>
<div class="app">
<!-- 父传子的写法1 -->
<abc :xixi="text"></abc>
<!-- 局部组件的两种写法 -->
<!-- <c></c> -->
<!-- 父传子的写法2 -->
<def></def>
<def :x="'2333 传了参数'"></def>
<!-- 子传父 -->
<def @click="get" :x="'2'"></def>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
// 父组件————>子组件 传数据 用!!props!!
// 方法1:在子组件定义一个数组(props:['xx']) > Vue-datd中写一个值(text:'xx') > <xx(子组件标签名) :xx(数组中的名字)="text" > 子组件中template写<h2>{{xx(数组中的名字)}}<h2>
// 方法2:在子组件定义一个对象(props:{xx:{}}) > <xx(子组件名) :xx(props里的xx) > 子组件中template写<h2>{{xx(props里的xx)}}<h2>
// 子组件————>父组件 $emit 借助这个把数据抛出去 $parent
// 全局组件(两个参数 '名字(不能是html默认标签的名字)',值(必须是{}))
Vue.component('abc', {//abc是标签名 可以随便取名
// template就是html标签 必须写
template: `
<div>
<h2>{{title}}</h2>
//父传子的写法1
<h2>{{xixi}}</h2>
</div>
`,
// 写法1
props: ['xixi'],
data() {
return {
title: '我是全局组件',
}
},
created() {
console.log("我是全局组件的生命周期:", this);
},
})
// 局部组件 def是变量名 不是标签名
var def = {
template: `
<div>
<h2>{{title}}</h2>
//父传子的写法2
<h2>{{x}}</h2>
//子传父
<h2 @click="submit">{{x}}</h2>
</div>`,
// 写法2
props: {
x: {
default: "父组件向子组件传数据方法2 没传参数默认写",
type: String
}
},
data() {
return {
title: '我是局部组件',
list: "子传父"
}
},
created() {
console.log("我是局部组件的生命周期:", this);
},
methods: {
submit() {
this.$emit("change", this.list)//两个参数 参数1:自定义名字 参数2:要抛出去的值
}
}
}
new Vue({
el: '.app',
data: {
text: '父组件向子组件传数据 方法1'
},
methods: {
get(val) {
console.log("父组件收到的数据:", val);
}
},
// 局部组件
components: {
// 方法一
//"c": def, //非简写
// 方法二
def //当名字和值一样时(def(标签名):def(变量名))可以简写为(def)
}
})
</script>
</html>