File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 8
8
nextTick ,
9
9
renderToString ,
10
10
ref ,
11
- defineComponent
11
+ defineComponent ,
12
+ createApp
12
13
} from '@vue/runtime-test'
13
14
14
15
describe ( 'api: options' , ( ) => {
@@ -105,6 +106,24 @@ describe('api: options', () => {
105
106
expect ( serializeInner ( root ) ) . toBe ( `<div>2</div>` )
106
107
} )
107
108
109
+ test ( 'component’s own methods have higher priority than global properties' , async ( ) => {
110
+ const app = createApp ( {
111
+ methods : {
112
+ foo ( ) {
113
+ return 'foo'
114
+ }
115
+ } ,
116
+ render ( ) {
117
+ return this . foo ( )
118
+ }
119
+ } )
120
+ app . config . globalProperties . foo = ( ) => 'bar'
121
+
122
+ const root = nodeOps . createElement ( 'div' )
123
+ app . mount ( root )
124
+ expect ( serializeInner ( root ) ) . toBe ( `foo` )
125
+ } )
126
+
108
127
test ( 'watch' , async ( ) => {
109
128
function returnThis ( this : any ) {
110
129
return this
Original file line number Diff line number Diff line change @@ -604,7 +604,17 @@ export function applyOptions(
604
604
for ( const key in methods ) {
605
605
const methodHandler = ( methods as MethodOptions ) [ key ]
606
606
if ( isFunction ( methodHandler ) ) {
607
- ctx [ key ] = methodHandler . bind ( publicThis )
607
+ // In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
608
+ // and those are read-only but reconfigurable, so it needs to be redefined here
609
+ if ( __DEV__ ) {
610
+ Object . defineProperty ( ctx , key , {
611
+ value : methodHandler . bind ( publicThis ) ,
612
+ configurable : true ,
613
+ enumerable : false
614
+ } )
615
+ } else {
616
+ ctx [ key ] = methodHandler . bind ( publicThis )
617
+ }
608
618
if ( __DEV__ ) {
609
619
checkDuplicateProperties ! ( OptionTypes . METHODS , key )
610
620
}
You can’t perform that action at this time.
0 commit comments