Browse Source

组件名称

master
邓宏 3 years ago
parent
commit
9932755c9e
  1. 11
      src/App.vue
  2. 104
      src/components/HelloWorld.vue
  3. 6
      src/main.js
  4. 10
      src/router/index.js
  5. 7
      src/views/Demo.vue
  6. 10
      src/views/Home.vue

11
src/App.vue

@ -2,15 +2,14 @@
import {useRouter} from 'vue-router'
const {push}=useRouter()
function to(e){
push({name:'demo'})
}
</script>
<template>
<div @click="to">demo</div>
<router-view />
<router-view v-slot="{Component}">
<keep-alive :include="['dhome','ddd']">
<component :is="Component" :key="$route.path"/>
</keep-alive>
</router-view>
</template>
<style>

104
src/components/HelloWorld.vue

@ -1,54 +1,90 @@
<script setup>
import { ref, useAttrs, useSlots, useCssVars, inject, defineExpose, onMounted } from 'vue'
console.log(inject("store"),'---------------store--------')
console.log(useAttrs(),'-------useAttrs-------')
console.log(useSlots(),'---------useSlots--')
defineProps({
msg: String
})
useCssVars(e=>{
console.log(e,"-----------ctx----")
})
const emit=defineEmits(['close'])
console.log(emit,'-------emit-----------')
const count = ref(0)
const color="#342e91"
defineExpose({ // 使
count
})
</script>
<style lang='less' scoped>
a {
color: #42b983;
background: v-bind(color);
}
.demo{
color:blue;
span{
font-weight: bold;
text-decoration: initial;
font-size:40px;
}
}
</style>
<style lang="less" module="cssName">
.demo{
color:red;
span{
font-weight: bold;
text-decoration: initial;
font-size:40px;
}
}
</style>
<template>
<h1 v-bind="$attrs">{{ msg }}</h1>
<slot/>
<slot name="demo"/>
<p>
<p v-my-directive>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
</p>
<p>
<!-- v-memo 类似于 v-one 数组内的值变换时会更新 -->
<p v-memo="[b]">
{{count}}
<a href="https://vitejs.dev/guide/features.html" target="_blank">
Vite Documentation
</a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
</p>
<div class="demo">1-<span>2</span></div>
<button type="button" @click="count++">count is: {{ count }}</button>
<p>
Edit
<p :class="cssName.demo">
<span>Edit</span>{{foo}}
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>
<script setup>
import { ref, useAttrs, useSlots, useCssVars, inject, defineExpose } from 'vue'
console.log(inject("store"),'---------------store--------')
console.log(useAttrs(),'-------useAttrs-------')
console.log(useSlots(),'---------useSlots--')
defineProps({
msg: String
})
useCssVars(e=>{
console.log(e,"-----------ctx----")
})
const emit=defineEmits(['close'])
console.log(emit,'-------emit-----------')
const count = ref(0)
const color="#342e91"
const b=ref('ddd')
window.b=b
defineExpose({ // 使
count
})
<style lang='less' scoped>
a {
color: #42b983;
background: v-bind(color);
}
</style>
const vMyDirective={
//
// attribute
created(el, binding, vnode) {},
//
beforeMount() {},
//
mounted() {},
// VNode
beforeUpdate() {},
// VNode VNode
updated() {},
//
beforeUnmount() {},
//
unmounted() {}
}
</script>

6
src/main.js

@ -4,7 +4,9 @@ import router from './router'
import store from '@/store'
console.log(import.meta.env,'--------------import------')
createApp(App)
.use(router)
var app=createApp(App)
app.use(router)
.use(store)
.mount('#app')
app.config.globalProperties.foo='===foo====' // 全局配置属性

10
src/router/index.js

@ -1,19 +1,21 @@
import { createRouter, createWebHashHistory } from "vue-router";
import Home from "@/views/home.vue";
import { defineAsyncComponent, defineComponent } from "vue";
var b=defineAsyncComponent(async()=>await import("@/views/demo.vue").then(v=>({...v.default,name:'ddd'})))
const routes = [
{
path: "/",
name: "Home",
component: Home,
name: "home",
component: {...Home,name:"dhome"},
},
{
path: "/demo",
name: "demo",
component: import("@/views/demo.vue"),
component: b,
},
];
window.r=routes
const router = createRouter({
history: createWebHashHistory(),
routes,

7
src/views/Demo.vue

@ -2,8 +2,13 @@
</style>
<template>
<h1>demo</h1>
<h1 @click="$router.go(-1)">demo page</h1>
</template>
<script setup>
import { onActivated } from "vue"
console.log("---------demo---------setup---------")
onActivated(()=>{
console.log("------demo-----------activated-------")
})
</script>

10
src/views/Home.vue

@ -2,9 +2,10 @@
</style>
<template>
<div @click="$router.push({path:'/demo'})">demo</div>
<img alt="Vue logo" src="~@/assets/img/logo.png" />
<hello-world msg="Hello Vue 3 + Vite" ref="hello" style="color:red;" class="hello">
<div>111</div>
<hello-world v-if="false" msg="Hello Vue 3 + Vite" ref="hello" style="color:red;" class="hello">
<div class="a">111</div>
<template #demo>
<div>2222222</div>
</template>
@ -13,9 +14,8 @@
<script setup>
// import HelloWorld from '@/components/HelloWorld.vue'
import { defineAsyncComponent, onMounted, ref } from 'vue'
var HelloWorld = defineAsyncComponent(()=>import('@/components/HelloWorld.vue'))
console.log("-------------home-------setup-----")
var hello=ref(null)
onMounted(()=>{
console.log(hello,'------------------hello----------')
})
</script>
Loading…
Cancel
Save