标签:bpa button main res 技术 ice ade 项目 css
自定义事件分发
组件内部绑定事件需要使用
this.$emit("函数名",参数)
如果组件想要删除vue里面的数据,就要通过前端。v-on:“组件里面函数名=“Vue里面的函数名”
组件
Vue.component("slot-item",{
props:["item","index"],
template: "<li>{{index}}--{{item}}<button @click=‘remove‘>删除</button></li>",
methods:{
remove:function (index) {
this.$emit("remove",index)
}
}
});
vue
methods: {
removeItems: function (index) {
this.items.splice(index,1)
}
}
前端
<div id="app">
<slot-wrap>
<slot-title slot="slot-title" v-bind:title="title"></slot-title>
<slot-item slot="slot-item" v-for="(item,index) in items"
v-bind:item="item" v-bind:index="index" v-on:remove="removeItems"></slot-item>
</slot-wrap>
</div>
不处理的话vue项目无法启动
解决方式:修改代理,如下
安装vue-router
在当前项目下安装路由npm install vue-router --save-dev
import Vue from ‘vue‘
import VueRouter from ‘vue-router‘
import Context from ‘../components/Context‘
import Main from ‘../components/Main‘
import Song from ‘../components/Song‘
// 安装路由
Vue.use(VueRouter);
// 配置导出路由
export default new VueRouter({
routes:[
{
// 路径
path:‘/context‘,
//跳转的组件
component:Context
},
{
// 路径
path:‘/main‘,
//跳转的组件
component:Main
},
{
// 路径
path:‘/song‘,
//跳转的组件
component:Song
}
]
});
<template>
<div id="app">
<h1>哈哈哈22</h1>
<router-link to="/main">首页</router-link>
<router-link to="/context">内容页</router-link>
<router-link to="/song">测试</router-link>
<router-view></router-view>
</div>
</template>
import Vue from ‘vue‘
import App from ‘./App‘
import router from ‘./router‘// 自动扫描里面的路由配置
Vue.config.productionTip = false;
new Vue({
el: ‘#app‘,
// 配置路由
router,
components: { App },
template: ‘<App/>‘
});
npm config rm proxy
npm config rm https-proxy
import Vue from ‘vue‘
import App from ‘./App‘
import router from ‘./router‘
import ElementUI from ‘element-ui‘;
import ‘element-ui/lib/theme-chalk/index.css‘;
import axios from ‘axios‘
import VueAxios from ‘vue-axios‘
Vue.use(VueAxios, axios)
Vue.use(router);
Vue.use(ElementUI);
Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
el: ‘#app‘,
router,
// components: { App },
// template: ‘<App/>‘,
render: h => h(App)
});
import Vue from ‘vue‘
import VueRouter from ‘vue-router‘
import Login from ‘../views/Login‘
import Main from ‘../views/Main‘
import UserProfile from‘../views/Profile‘
import UserList from‘../views/List‘
import Not from‘../views/Notfond‘
Vue.use(VueRouter);
export default new VueRouter({
mode:‘history‘,// 去除地址中#
routes:[
{
path:"/login",
component:Login,
},
{
path:‘/main/:pass‘,
component:Main,
props:true,
children:[
{path:‘/user/list‘,component:UserList},
{path:‘/user/profile/:id‘,name:‘UserProfile‘,component:UserProfile,props:true}
]
},
{
path:"/gohome",
redirect:"/main"
},
{
path:"*",
component:Not
}
]
});
<router-link to="/user/list">用户管理</router-link>
<el-col :span="8">
<router-view></router-view>
</el-col>
import ElementUI from ‘element-ui‘;
import ‘element-ui/lib/theme-chalk/index.css‘;
Vue.use(ElementUI);
{
path:‘/main/:pass‘,
component:Main,
props:true,
children:[
{path:‘/user/list‘,component:UserList},
{path:‘/user/profile/:id‘,name:‘UserProfile‘,component:UserProfile,props:true}
]
},
this.$router.push(‘/main/‘+this.ruleForm.pass)//获取登录页面的用户名
index.js文件中路径写法:{path:‘/main/:pass‘}
<router-link :to="{name:‘UserProfile(组件名)‘,params:{id:123}}">文件管理</router-link>
{path:‘/user/profile/:id‘,name:‘UserProfile‘,component:UserProfile,props:true}// index格式
profile.vue 通过props: ["id"],获取参数 并通过{{id}}显示在页面上或者直接 <!--{{$route.params.id}}-->显示在页面上
{
path:"/gohome",
redirect:"/main"
}
{
path:"*",
component:Not
}
<script>
export default {
props: ["id"],
name: "UserProfile",
beforeRouteEnter(to,from,next){
console.log("进入钩子函数之前");
next(vm => {
vm.getData();// 进入路由之前执行getDaTa()
});
},
beforeRouteLeave(to,from,next){
console.log("离开钩子函数之前");
next();
},
methods:{
getData:function () {
this.axios({
method:‘get‘,
url:‘http://localhost:8080/static/mock/data.json‘
}).then(function (response) {
console.log(response);
});
}
}
}
</script>
标签:bpa button main res 技术 ice ade 项目 css
原文地址:https://www.cnblogs.com/sxyuyu/p/12628758.html