$(window).width() 在vue中怎么书写
时间: 2024-05-09 12:18:12 浏览: 7
您可以使用 computed 属性来获取窗口当前的宽度:
```
computed: {
windowWidth() {
return window.innerWidth;
}
}
```
在这个例子中,我们使用 window.innerWidth 来获取窗口当前的宽度,然后使用 computed 属性来保存返回值。这使得我们可以在 HTML 模板中使用 windowWidth 属性来获取窗口的宽度。
相关问题
this.$router.resolve和$router.push 区别
this.$router.resolve和$router.push都是Vue Router中的方法,用于导航到不同的路由。
this.$router.push用于在当前窗口中导航到指定的路由。它接收一个路由对象作为参数,通过指定路由的名称、参数、查询等信息来生成目标路径,并进行导航跳转。例如,this.$router.push({name: 'details', params: {'id': 233}})表示要导航到名为details的路由,并且传递了id参数为233。这个方法会改变当前的URL,并加载相应的组件。
而this.$router.resolve方法不会进行实际的导航跳转,它只是用于解析目标路由的信息。它也接收一个路由对象作为参数,并返回一个包含目标路由信息的对象。这个方法可以用于获取目标路由的URL,以便在新窗口中打开。例如,const {href} = this.$router.resolve({name: 'foo', query: { bar }})会生成名为foo的路由的URL,并将其赋值给href变量,然后可以使用window.open方法在新窗口中打开这个URL。
所以,$router.push用于实际的导航跳转,而$router.resolve用于解析目标路由的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [详解新手使用vue-router传参时注意事项](https://download.csdn.net/download/weixin_38557980/13590198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [vue的跳转方式——window.open & router-link标签 & this.$router.push跳转 & this.$router.replace跳转 & ...](https://blog.csdn.net/weixin_44867717/article/details/120503404)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
Vue window.location.href
在Vue中,可以使用window.location.href来在当前窗口中打开一个新的URL,比如可以使用window.location.href = 'https://www.cnblogs.com/guorongtao/'来在当前窗口中打开博客园的个人博客页面。这与在JavaScript中使用window.location.href的方式类似。在HTML中,可以使用<a href="https://www.cnblogs.com/guorongtao/">Welcome Test1</a>来创建一个链接,点击链接时会在新窗口中打开指定的URL。另外,如果你想在Vue中打开一个新的窗口,并指定窗口的大小、位置等参数,可以使用window.open来实现,例如:window.open('www.baidu.com','newindow','height=600,width=900,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')。另外,如果你想在Vue中打开一个模态对话框(Modal Dialog),可以使用window.showModalDialog来实现,例如:window.showModalDialog('https://www.cnblogs.com/guorongtao','','DialogLeft:170px;DialogTop:130px;DialogWidth:930px;DialogHeight:753px;status:no;help:no')。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Window 打开新窗口的几种方式 window.location.href、window.open、window.showModalDialog](https://blog.csdn.net/qianluo111/article/details/125280622)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]