您能否建议一下新的 Vue 组合 API 中的 等效项是什么created(),我在 Vue2 中使用它,如下所示:
import { reactive, toRefs } from '@vue/composition-api'
Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有vuejs的网站,此时我遇到了麻烦,我需要从这个网站上获取网址查询(页面),例如这个网站webitename.com/user/?page=1但是this.$router.query.page得到了一个错误(未捕获的TypeError:无法读取undefined的属性"page"
有人知道这个问题,可以帮助我吗?
PS:我可以使用设置查询页面
this.$router.push({name: 'userIndex', query: { page: '123' } });
Run Code Online (Sandbox Code Playgroud)
我可以得到像这样的url normal params
userID -> (websitename.com/user/:userId | websitename.com/user/1)
Run Code Online (Sandbox Code Playgroud)
但我无法获得任何查询参数
我在这个拉动请求中看到:
添加router.reload()
重新加载当前路径并再次调用数据挂钩
但是当我尝试从Vue组件发出以下命令时:
this.$router.reload()
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
router.reload()
我搜索了文档,但找不到任何相关内容.vue/vue-router提供者有这样的功能吗?
我感兴趣的软件版本是:
"vue": "^2.1.0",
"vue-router": "^2.0.3",
Run Code Online (Sandbox Code Playgroud)
PS.我知道Uncaught TypeError: this.$router.reload is not a function是其中一个选择,但我正在寻找一个原生的Vue选项.
我正在用Vue.js创建一个组件.
当我引用this中的任何所述的生命周期钩(created,mounted,updated等等)它的计算结果为undefined:
mounted: () => {
console.log(this); // logs "undefined"
},
Run Code Online (Sandbox Code Playgroud)
在我的计算属性中也发生了同样的事情:
computed: {
foo: () => {
return this.bar + 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
未捕获的TypeError:无法读取未定义的属性"bar"
为什么在这些情况下进行this评估undefined?
我正在使用Vue ESLint 插件,它有一条不允许使用单字组件名称的规则。
但是,我也在使用 Nuxt,要在 Nuxt 中设置默认布局,您需要一个名为的 .vue 组件default.vue,该组件会引发 ES Lint 规则错误。
我似乎无法在那个实际上很小的 .vue 文件中禁用它......
<template>
<div>
<Header/>
<Nuxt/>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
但如果我禁用我的规则,.eslintrc.js那么它就会起作用。
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
'@nuxtjs/eslint-config-typescript',
'plugin:nuxt/recommended',
'prettier',
],
plugins: [],
// add your custom rules here
rules: {
'vue/multi-word-component-names': 'off',
},
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以仅对一个 Vue 文件禁用该规则?
我正在为一个小应用程序使用Vue.js 2.0和Vuex 2.0.我正在通过调用从API检索初始状态的操作初始化根Vue实例上的'created'生命周期钩子中的存储....就像在我的根组件中一样:
const app = new Vue({
el: "#app",
router,
store,
data: {
vacation: {},
},
components: {
'vacation-status': VacationStatus,
},
created(){
//initialize store data structure by submitting action.
this.$store.dispatch('getVacation');
},
computed: {
},
methods: {
}
});
Run Code Online (Sandbox Code Playgroud)
这工作得很好.这是我在这里打电话给我的商店的行动:
getVacation({commit}){
api.getVacation().then(vacation => commit(UPDATE_VACATION, vacation))
}
Run Code Online (Sandbox Code Playgroud)
这与'UPDATE_VACATION'提交的变异在这里:
[UPDATE_VACATION] (state, payload) {
state.vacation = payload.vacation;
},
Run Code Online (Sandbox Code Playgroud)
我的问题:当我加载应用程序时,所有从商店"获取"值的组件会抛出错误,我试图访问商店中的"未定义"值.换句话说,状态尚未初始化.
例如,我有一个组件在子组件中具有getter,如下所示:
computed: {
arrival () {
return this.$store.getters.arrival
},
departure() {
return this.$store.getters.departure
},
countdown: function() {
return this.$store.getters.countdown …Run Code Online (Sandbox Code Playgroud) 好的,简单地解释一下:
我有3x页面.
第1页有 -
<router-link to="/menu">
Run Code Online (Sandbox Code Playgroud)
点击的按钮路由到"/ menu".
目前,第2页(菜单)有一个
<router-link to="/">
Run Code Online (Sandbox Code Playgroud)
按钮,单击此按钮时,它将恢复到之前的位置"/"Page 1(Home).
但我不想为每个页面创建路由器组件以"返回"到上一页(就好像我有100页这可能是很多工作路由回来).有没有办法用vue-router做到这一点?类似于window.history.back()
很想知道是否有办法这样做,因为我在文档中找不到它.
提前致谢!约翰
我的vuex商店里有两个模块.
var store = new Vuex.Store({
modules: {
loading: loading
posts: posts
}
});
Run Code Online (Sandbox Code Playgroud)
在该模块中loading,我有一个属性saving,其可以被设置true或false也有一个名为变异函数TOGGLE_SAVING来设置该属性.
在模块中posts,在获取帖子之前和之后,我想要更改属性saving.我是通过调用模块commit('TOGGLE_SAVING')中的一个动作来完成的posts.
var getPosts = function (context) {
contex.commit(TOGGLE_LOADING);
};
Run Code Online (Sandbox Code Playgroud)
当它尝试提交时,我在控制台中出现以下错误
[vuex] unknown local mutation type: TOGGLE_LOADING, global type: posts/TOGGLE_LOADING
Run Code Online (Sandbox Code Playgroud)
如何在另一个模块中使用变异状态commit?
如何访问vue.js应用程序中的JSON对象我是新手
import json from './json/data.json'
Run Code Online (Sandbox Code Playgroud)
加载JSON文件,现在我必须访问其中的对象
我有一个包含以下哈希的组件
{
computed: {
isUserID: {
get: function(){
return this.userId?
}
}
}
Run Code Online (Sandbox Code Playgroud)
我应该观看isUserID还是userId改变?你能看到计算属性吗?
vuejs2 ×10
vue.js ×8
javascript ×3
vue-router ×3
vuex ×2
eslint ×1
eslintrc ×1
nuxt.js ×1
this ×1
webpack ×1