for example, I pass a method in the parent component, but what should I do if it is executed in the child component? Do not use $emit
for example, I pass a method in the parent component, but what should I do if it is executed in the child component? Do not use $emit
methods. The more common one is to define a Function parameter in the porps
of the child component, and the parent component passes the method as a parameter
subcomponent code snippet
export default {
name: 'Children',
props: {
parentMethod: Function,
},
methods: {
onClick() {
this.parentMethod();
},
parent component code snippet
<template>
<children :parent-method="testMethod"></children>
</template>
<script>
export default {
methods: {
testMethod() {
console.log('test');
},
in this way, when the child component triggers onClick
, the parent component's testMethod
is called. Although the process is not as clear as $on
+ $emit
, it is still very maintainable
Previous: How to filter this array? Algorithm
Next: In dvajs, ie10 class does not report errors, but use charts such as bizchart to report errors.
how do Vue projects built with Nuxt.js share header and footer files? only files with section contents are placed in the page directory. Navigation bars and footers and every time you jump to a new route, navigation doesn t have to be reloaded. Gods, ...
nuxt 1.4 uses keepAlive, in nuxt, but I find that when the page component is switched, the data in data will be reset and emptied when entering the interface . Is this his bug? if there is a problem with the setting, how can I modify the setting? ...
the packaged scripts are generated dynamically by nuxt. How to mark a global variable so that your business code can tell which command it is? (for example, the interface domain names of different commands are different) ...
ask nuxt.js s vue single file, how to make some vue scripts to be rendered by browser instead of server. if the pull-up load belongs to browser rendering through ajax, how to express the .vue single file in ssr mode. Please, everyone. I m in a hurry...
add components with npm install v-distpicker add vendor: to nuxt.config.js [ axios , v vendor: distressed ] how to write in the vue interface, ask the great gods to save ...
I use the npm run dev command, but I use npm run generate to package and generate the dist folder, and open index.html to find that js is all invalid. When I first met vue, I asked for guidance. ...
I have a configuration file in js format, and I don t want to read the configuration every time I have a request. (what if I configure it in cdn,? (not so good on the server Synchronize in the past) if I am writing a service like golang php c, I will c...
page: structure: index.vue homeindex.vue :homeindex.vuevue-awesome-swiper: ...
the project directory automatically generated by nuxt.js no longer has webpack.config.js, so how to configure things such as scss, less, autoprefixer, and url? ...
I need the js file in plugins or assets to call the mutation method add . How can I call it correctly? ...
I want to use this in asyncData () in the Nuxt.js project it is officially said that this cannot be used in asyncData (), but my business requirement is to send a variable managed by vuex to the server when the page is loaded. The data code is as foll...
this relative module was not found ...
I put the configuration file of axios in plugins axios.js with the following code: import axios from axios import qs from qs const hotName = location.hostname if (hotName === localhost ) { axios.defaults.baseURL = ` xxxx.com api` axios...
.eslintrc.js is configured as follows description: The problem with is plugin:vue essential . If you comment it out, vscode will work properly. npm run dev can run normally and will not report an error of export . Of course, an error ...
No response to interface requests in asyncData api.jsaxiosstatic: I put the request in mounted so that I can request it successfully ...
A new project that has just been completed takes into account the problem of seo after it is launched. It uses prerender-spa-plugin to pre-render the page, but the dynamic routing page can not achieve the rendering effect. More often, the meta informatio...
when users are not logged in, they enter the login page by default, while the login page has a "about us " button. Click to enter the page about us. Click on this.$router.,. Now the problem is to enter the page about us from the login page, refresh and ...
suppose that two modules an and b are defined in vuex, and how can action in SET_USER,a be called if there is a mutations method in b? I try to directly store.commit( SET_USER , user); but the prompt cannot find this mutations,. It seems that the c...
in the website built by nuxt.js, a request is sent in the asyncData method on the home page. The interface address is forwarded with nginx. The background log checks the returned data, but the front end does not receive the returned data. The website ca...
< H1 > the code is as follows < H1 > package.json { "name": "example-hello-world", "dependencies": { "nuxt": "latest" }, "scripts": { "dev": "nuxt", &...