vue获取当前页面的路由,判断是否为指定页面

vue获取当前页面的路由,判断是否为指定页面

需求

项目中有时需要判断当前是否某个页面,只有指定页面执行该方法,其他界面不执行。

代码

<script>
export default {
	name: 'MyInterface',
	methods: {
		// 判断是否是当前界面
		isMyInterface() {
			// 获取当前路由页面的name
			const urlName = this.$route.name
			if (urlName === 'MyInterface') {
				// 是当前界面
				...
			}
		}
	}
}
   

你可能感兴趣的:(前端,vue.js,前端,javascript)